Merge branch 'add_redirects' of github.com:sclements/scratch-www into s3

# Conflicts:
#	.eslintrc
#	server/handler.js
This commit is contained in:
Ray Schamp 2016-04-19 16:56:22 -04:00
commit 59227e3272
5 changed files with 17 additions and 7 deletions

View file

@ -20,8 +20,9 @@
"formatMessage": true "formatMessage": true
}, },
"ecmaFeatures": { "ecmaFeatures": {
"jsx": true, "arrowFunctions": true,
"blockBindings": true "blockBindings": true,
"jsx": true
}, },
"plugins": [ "plugins": [
"react" "react"

View file

@ -2,8 +2,12 @@
* Constructor * Constructor
*/ */
function Handler (route) { function Handler (route) {
var url = '/' + route.view + '.html'; // Handle redirects
if (route.redirect) {
return (req, res) => { res.redirect(route.redirect); };
}
var url = '/' + route.view + '.html';
return function (req, res, next) { return function (req, res, next) {
req.url = url; req.url = url;
next(); next();

View file

@ -16,10 +16,9 @@ app.disable('x-powered-by');
app.use(log()); app.use(log());
// Bind routes // Bind routes
for (var routeId in routes) { routes.forEach(route => {
var route = routes[routeId];
app.get(route.pattern, handler(route)); app.get(route.pattern, handler(route));
} });
app.use(webpackDevMiddleware(compiler)); app.use(webpackDevMiddleware(compiler));

View file

@ -43,5 +43,9 @@
"pattern": "^/wedo$", "pattern": "^/wedo$",
"view": "wedo2", "view": "wedo2",
"title": "LEGO WeDo 2.0" "title": "LEGO WeDo 2.0"
},
{
"pattern": "/info/donate/",
"redirect": "https://secure.donationpay.org/scratchfoundation/"
} }
] ]

View file

@ -11,7 +11,9 @@ var entry = {
init: './src/init.js' init: './src/init.js'
}; };
routes.forEach(function (route) { routes.forEach(function (route) {
if (!route.redirect) {
entry[route.view] = './src/views/' + route.view + '/' + route.view + '.jsx'; entry[route.view] = './src/views/' + route.view + '/' + route.view + '.jsx';
}
}); });
// Config // Config