mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-26 09:08:07 -05:00
Use environment for proxy settings
Also use default local scratchr2 port, 8080.
This commit is contained in:
parent
69820aed6e
commit
8d574399e5
3 changed files with 12 additions and 6 deletions
2
.env.sample
Normal file
2
.env.sample
Normal file
|
@ -0,0 +1,2 @@
|
|||
PROXY_HOST=http://localhost
|
||||
PROXY_PORT=8080
|
|
@ -14,8 +14,8 @@ app.use(log());
|
|||
app.use(compression());
|
||||
|
||||
// Bind routes
|
||||
for (var rId in routes) {
|
||||
var route = routes[rId];
|
||||
for (var routeId in routes) {
|
||||
var route = routes[routeId];
|
||||
if ( route.static ) {
|
||||
app.use( express.static( eval( route.resolve ), route.attributes ) );
|
||||
} else {
|
||||
|
@ -27,9 +27,11 @@ for (var rId in routes) {
|
|||
if ( process.env.ENVIRONMENT == 'development' ) {
|
||||
var proxies = require('./proxies.json');
|
||||
var url = require('url');
|
||||
for (var pId in proxies) {
|
||||
var proxyRoute = proxies[pId];
|
||||
app.use(proxyRoute.root, proxy(proxyRoute.proxy, {
|
||||
var proxyHost = process.env.PROXY_HOST || 'http://localhost';
|
||||
proxyHost += ':' + (process.env.PROXY_PORT || 8080);
|
||||
for (var proxyId in proxies) {
|
||||
var proxyRoute = proxies[proxyId];
|
||||
app.use(proxyRoute.root, proxy(proxyRoute.proxy || proxyHost, {
|
||||
filter: function (req) {
|
||||
return proxyRoute.paths.indexOf(url.parse(req.url).path) > -1;
|
||||
},
|
||||
|
@ -44,4 +46,7 @@ if ( process.env.ENVIRONMENT == 'development' ) {
|
|||
var port = process.env.PORT || 8333;
|
||||
app.listen(port, function () {
|
||||
process.stdout.write('Server listening on port ' + port + '\n');
|
||||
if (proxyHost) {
|
||||
process.stdout.write('Proxy host: ' + proxyHost + '\n');
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[
|
||||
{
|
||||
"proxy": "http://localhost:8000",
|
||||
"root": "/",
|
||||
"paths": [
|
||||
"/session/",
|
||||
|
|
Loading…
Reference in a new issue