mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
1a8691bc53
Otherwise we’d have to change the mapping every time we add or remove a chunk.
29 lines
819 B
JavaScript
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;
|