2016-06-02 16:42:00 +02:00
|
|
|
/* eslint-disable strict, no-console */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
2016-06-02 15:31:21 +02:00
|
|
|
const express = require('express');
|
|
|
|
const compression = require('compression');
|
|
|
|
const removeTrailingSlash = require('remove-trailing-slash');
|
2015-06-10 15:42:35 +02:00
|
|
|
|
2016-06-02 15:31:21 +02:00
|
|
|
const BASE_PATH = removeTrailingSlash(process.env.ONION_BASE_PATH || '/');
|
|
|
|
const PORT = process.env.ONION_PORT || 4000;
|
2015-06-08 17:20:08 +02:00
|
|
|
|
2016-06-02 15:31:21 +02:00
|
|
|
const app = express();
|
2015-06-08 15:24:58 +02:00
|
|
|
|
2015-06-08 17:26:27 +02:00
|
|
|
app.use(compression());
|
2016-06-02 17:08:59 +02:00
|
|
|
app.use(path.resolve(BASE_PATH, '/static'), express.static(path.resolve(__dirname, 'dist')));
|
2015-06-08 15:24:58 +02:00
|
|
|
|
2016-06-02 16:42:00 +02:00
|
|
|
app.get(/.*/, (req, res) => {
|
2015-06-16 19:28:21 +02:00
|
|
|
console.log('%s %s', req.method, req.path);
|
2016-06-02 15:31:21 +02:00
|
|
|
res.sendFile(path.resolve(__dirname, 'dist/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) {
|
2016-06-02 15:31:21 +02:00
|
|
|
console.log(`Starting Onion server on port ${PORT} with basePath set to ${BASE_PATH || '/'}`);
|
|
|
|
app.listen(PORT);
|
2015-06-08 15:24:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.app = app;
|