Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/makeserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var cors = require('cors');
var exists = require('./exists');
var basicAuth = require('basic-auth');
var fs = require('fs');
var URI = require("urijs");
var ExpressBrute = require('express-brute');

/* Creates and returns a single express server. */
Expand Down Expand Up @@ -145,6 +146,22 @@ module.exports = function(options) {
var error500 = errorPage.error500(show500, options.wwwroot);
var initPaths = options.settings.initPaths || [];

// Serve up prerendered pages if they exist for a given route
app.get('*', function (req, res, next) {
const decodedPath = URI.decode(req.path);
const prerendered = path.resolve(options.wwwroot, `prerendered/${decodedPath}`, 'index.html');

if (fs.existsSync(prerendered)) {
res.sendFile(prerendered);
// Other /catalog/ routes should at least return index.html, in case of unresolved pathing/id
} else if (decodedPath.substr(0,9) === "/catalog/") {
res.sendFile(options.wwwroot + '/index.html');
} else {
// For now, don't resolve remaining app urls SPA-style with all-routes-200-index.html
next();
}
});

if (serveWwwRoot) {
initPaths.push(path.join(options.wwwroot, 'init'));
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "terriajs-server",
"version": "3.1.0",
"version": "3.1.0-new-routing",
"description": "NodeJS server for TerriaJS, consisting of a CORS proxy, proj4 CRS lookup service, ogr2ogr conversion service, and express static server.",
"engineStrict": true,
"engines": {
Expand Down Expand Up @@ -44,12 +44,13 @@
"json5": "^2.1.0",
"morgan": "^1.7.0",
"pm2": "^3.2.2",
"terriajs-ogr2ogr": "^1.0.0",
"proj4": "^2.3.12",
"proj4js-defs": "0.0.1",
"range_check": "^1.4.0",
"request": "^2.67.0",
"request-promise": "^4.0.1",
"terriajs-ogr2ogr": "^1.0.0",
"urijs": "^1.18.12",
"when": "^3.7.7",
"yargs": "^13.2.4"
},
Expand Down
4 changes: 4 additions & 0 deletions serverconfig.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Port to listen on. Overriden by the --port command line setting.
port: 3001,

// If you are serving TerriaMap from a directory, specify the path to it here,
// otherwise leave it as '/' for root paths
baseHref: "/",

// List of domains which the server is willing to proxy for. Subdomains are included automatically.
allowProxyFor : [
"nicta.com.au",
Expand Down