From 393552bd463b5274469d4fa2bc96baed8aa39109 Mon Sep 17 00:00:00 2001 From: Colby Gutierrez-Kraybill Date: Mon, 14 Sep 2015 12:16:58 -0400 Subject: [PATCH] Adding annotations to routes.json and correct interpreting code to include information about static assets. Will be used by routes-to-nginx-conf for building nginx regex patterns --- package.json | 1 + server/index.js | 10 +++++----- server/routes.json | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 0ba95f282..27ecfdb3e 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "react": "0.13.3", "react-modal": "0.3.0", "react-slick": "0.7.0", + "routes-to-nginx-conf": "0.0.2", "sass-loader": "2.0.1", "slick-carousel": "1.5.8", "style-loader": "0.12.3", diff --git a/server/index.js b/server/index.js index b12576a5d..5e027cbf4 100644 --- a/server/index.js +++ b/server/index.js @@ -11,15 +11,15 @@ var app = express(); app.disable('x-powered-by'); app.use(log()); app.use(compression()); -app.use(express.static(path.resolve(__dirname, '../build'), { - lastModified: true, - maxAge: '1y' -})); // Bind routes for (var item in routes) { var route = routes[item]; - app.get(route.pattern, handler(route)); + if ( route.static ) { + app.use( express.static( eval( route.resolve ), route.attributes ) ); + } else { + app.get(route.pattern, handler(route)); + } } // Start listening diff --git a/server/routes.json b/server/routes.json index 1e07b5438..9131e4645 100644 --- a/server/routes.json +++ b/server/routes.json @@ -1,15 +1,24 @@ [ { "pattern": "/", - "view": "splash" + "view": "splash", + "static": false }, { "pattern": "/about", "view": "about", - "title": "About" + "title": "About", + "static": false }, { "pattern": "/components", - "view": "components" + "view": "components", + "static": false + }, + { + "static": true, + "resolve": "path.resolve(__dirname, '../build')", + "attributes": { "lastModified": true, "maxAge": "1y" }, + "_todo": " TODO: Define a specification for how each entry is used/expected to look like, given the nginx conf generator's needs and stand-alone run-time needs. An outline of this so far: static requires resolve/attributes but could use pattern too. ..." } ]