mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-30 02:56:20 -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());
|
app.use(compression());
|
||||||
|
|
||||||
// Bind routes
|
// Bind routes
|
||||||
for (var rId in routes) {
|
for (var routeId in routes) {
|
||||||
var route = routes[rId];
|
var route = routes[routeId];
|
||||||
if ( route.static ) {
|
if ( route.static ) {
|
||||||
app.use( express.static( eval( route.resolve ), route.attributes ) );
|
app.use( express.static( eval( route.resolve ), route.attributes ) );
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,9 +27,11 @@ for (var rId in routes) {
|
||||||
if ( process.env.ENVIRONMENT == 'development' ) {
|
if ( process.env.ENVIRONMENT == 'development' ) {
|
||||||
var proxies = require('./proxies.json');
|
var proxies = require('./proxies.json');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
for (var pId in proxies) {
|
var proxyHost = process.env.PROXY_HOST || 'http://localhost';
|
||||||
var proxyRoute = proxies[pId];
|
proxyHost += ':' + (process.env.PROXY_PORT || 8080);
|
||||||
app.use(proxyRoute.root, proxy(proxyRoute.proxy, {
|
for (var proxyId in proxies) {
|
||||||
|
var proxyRoute = proxies[proxyId];
|
||||||
|
app.use(proxyRoute.root, proxy(proxyRoute.proxy || proxyHost, {
|
||||||
filter: function (req) {
|
filter: function (req) {
|
||||||
return proxyRoute.paths.indexOf(url.parse(req.url).path) > -1;
|
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;
|
var port = process.env.PORT || 8333;
|
||||||
app.listen(port, function () {
|
app.listen(port, function () {
|
||||||
process.stdout.write('Server listening on port ' + port + '\n');
|
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": "/",
|
"root": "/",
|
||||||
"paths": [
|
"paths": [
|
||||||
"/session/",
|
"/session/",
|
||||||
|
|
Loading…
Reference in a new issue