Merge pull request #80 from thisandagain/bugfix/nginx

Remove nginx build process and clean-up for production
This commit is contained in:
Ray Schamp 2015-10-20 13:27:42 -04:00
commit 6cdc447e83
5 changed files with 37 additions and 58 deletions

View file

@ -1,6 +1,6 @@
ESLINT=./node_modules/.bin/eslint
SASSLINT=./node_modules/.bin/sass-lint -v
NODE=node
SASSLINT=./node_modules/.bin/sass-lint -v
WATCH=./node_modules/.bin/watch
WEBPACK=./node_modules/.bin/webpack
@ -43,11 +43,6 @@ start:
# ------------------------------------
nginx_conf:
node server/nginx.js
# ------------------------------------
test:
@make lint
@ -65,4 +60,4 @@ lint:
# ------------------------------------
.PHONY: build clean static webpack watch stop start nginx_conf test lint
.PHONY: build clean static translations webpack watch stop start test lint

View file

@ -4,11 +4,13 @@ if (typeof process.env.NEW_RELIC_LICENSE_KEY === 'string') {
var compression = require('compression');
var express = require('express');
var path = require('path');
var proxy = require('express-http-proxy');
var _path = require('path');
var url = require('url');
var handler = require('./handler');
var log = require('./log');
var proxies = require('./proxies.json');
var routes = require('./routes.json');
// Server setup
@ -16,37 +18,36 @@ 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'
}));
app.use(function (req, res, next) {
req._path = url.parse(req.url).path;
next();
});
// Bind routes
for (var routeId in routes) {
var route = routes[routeId];
if ( route.static ) {
app.use( express.static( eval( route.resolve ), route.attributes ) );
} else {
app.get(route.pattern, handler(route));
}
app.get(route.pattern, handler(route));
}
// Bind proxies in development
if ( process.env.NODE_ENV != 'production' ) {
var proxies = require('./proxies.json');
var url = require('url');
if (process.env.NODE_ENV !== 'production') {
var proxyHost = process.env.PROXY_HOST || 'https://staging.scratch.mit.edu';
for (var proxyId in proxies) {
var proxyRoute = proxies[proxyId];
app.use(proxyRoute.root, proxy(proxyRoute.proxy || proxyHost, {
filter: function (req) {
for (var pathId in proxyRoute.paths) {
var path = proxyRoute.paths[pathId];
if (url.parse(req.url).path.indexOf(path) == 0) return true;
}
return false;
},
forwardPath: function (req) {
return url.parse(req.url).path;
app.use('/', proxy(proxyHost, {
filter: function (req) {
for (var i in proxies) {
if (req._path.indexOf(proxies[i]) === 0) return true;
}
}));
}
return false;
},
forwardPath: function (req) {
return req._path;
}
}));
}
// Start listening

View file

@ -1,5 +0,0 @@
var routes = require('./routes.json');
var nginx_conf = require('routes-to-nginx-conf');
nginx_conf.generate_nginx_conf( routes, function ( v ) { process.stdout.write(v); } );

View file

@ -1,14 +1,9 @@
[
{
"root": "/",
"paths": [
"/accounts/",
"/csrf_token/",
"/fragment/",
"/get_image/",
"/login_retry",
"/session/",
"/static/"
]
}
"/accounts/",
"/csrf_token/",
"/fragment/",
"/get_image/",
"/login_retry",
"/session/",
"/static/"
]

View file

@ -2,28 +2,21 @@
{
"pattern": "/",
"view": "splash",
"static": false
"title": "Imagine, Program, Share"
},
{
"pattern": "/about",
"view": "about",
"title": "About",
"static": false
"title": "About"
},
{
"pattern": "/components",
"view": "components",
"static": false
"title": "Components"
},
{
"pattern": "/hoc",
"view": "hoc",
"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. ..."
"title": "Hour of Code"
}
]