1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00
onion/server.js

29 lines
819 B
JavaScript
Raw Normal View History

/* eslint-disable strict, no-console */
'use strict';
const path = require('path');
const express = require('express');
const compression = require('compression');
const removeTrailingSlash = require('remove-trailing-slash');
2015-06-10 15:42:35 +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
const app = express();
2015-06-08 15:24:58 +02:00
2015-06-08 17:26:27 +02:00
app.use(compression());
app.use(path.resolve(BASE_PATH, '/static'), express.static(path.resolve(__dirname, 'dist')));
2015-06-08 15:24:58 +02:00
app.get(/.*/, (req, res) => {
2015-06-16 19:28:21 +02:00
console.log('%s %s', req.method, req.path);
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) {
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;