1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/server.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2015-06-09 17:53:44 +02:00
var argv = require('yargs').argv;
2015-06-08 15:24:58 +02:00
var express = require('express');
2015-06-10 15:42:35 +02:00
var compression = require('compression');
2015-06-09 17:53:44 +02:00
var baseUrl = (function () { var baseUrl = process.env.ONION_BASE_URL || '/'; return baseUrl + (baseUrl.match(/\/$/) ? '' : '/'); })();
2015-06-08 17:20:08 +02:00
2015-06-08 15:24:58 +02:00
var app = express();
2015-06-08 17:26:27 +02:00
app.use(compression());
2015-06-08 17:20:08 +02:00
2015-06-09 17:53:44 +02:00
app.use(baseUrl + 'static/js', express.static(__dirname + '/build/js'));
2015-06-16 09:57:14 +02:00
app.use(baseUrl + 'static/img', express.static(__dirname + '/build/img'));
2015-06-09 17:53:44 +02:00
app.use(baseUrl + 'static/css', express.static(__dirname + '/build/css'));
app.use(baseUrl + 'static/fonts', express.static(__dirname + '/build/fonts'));
2015-06-16 19:28:21 +02:00
app.use(baseUrl + 'static/thirdparty', express.static(__dirname + '/node_modules'));
2015-06-08 15:24:58 +02:00
app.get(/.*/, function(req, res) {
2015-06-16 19:28:21 +02:00
console.log('%s %s', req.method, req.path);
2015-06-09 17:53:44 +02:00
res.sendFile(__dirname + '/build/index.html');
2015-06-08 15:24:58 +02:00
});
2015-06-16 19:28:21 +02:00
2015-06-08 15:24:58 +02:00
if (require.main === module) {
2015-06-16 19:28:21 +02:00
var port = process.env.PORT || 4000;
console.log('Starting Onion server on port', port,
'baseUrl is set to', baseUrl);
app.listen(port);
2015-06-08 15:24:58 +02:00
}
module.exports.app = app;