1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-15 17:13:16 +02:00
onion/server.js
Brett Sun 1a8691bc53 Map entire dist/ folder as /static in server to allow for dynamic chunking
Otherwise we’d have to change the mapping every time we add or remove a
chunk.
2016-06-03 13:26:43 +02:00

29 lines
819 B
JavaScript

/* 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');
const BASE_PATH = removeTrailingSlash(process.env.ONION_BASE_PATH || '/');
const PORT = process.env.ONION_PORT || 4000;
const app = express();
app.use(compression());
app.use(path.resolve(BASE_PATH, '/static'), express.static(path.resolve(__dirname, 'dist')));
app.get(/.*/, (req, res) => {
console.log('%s %s', req.method, req.path);
res.sendFile(path.resolve(__dirname, 'dist/index.html'));
});
if (require.main === module) {
console.log(`Starting Onion server on port ${PORT} with basePath set to ${BASE_PATH || '/'}`);
app.listen(PORT);
}
module.exports.app = app;