fetch-dht/index.js
2020-04-12 16:33:32 -05:00

41 lines
911 B
JavaScript

const express = require('express');
const path = require('path');
const serveStatic = require('serve-static');
require('dotenv').config();
const DHT = require('./lib/dht');
const log = require('./lib/log');
const config = process.env;
const dht = new DHT(config.DHT_PORT);
const app = express();
app.use(log.middleware);
app.use(require('./routes')({ dht }));
app.use(
serveStatic(path.resolve(__dirname, 'static'), {
acceptRanges: false,
dotfiles: 'ignore',
etag: true,
extensions: false,
fallthrough: true,
immutable: false,
index: 'index.html',
lastModified: false,
maxAge: '1d',
redirect: false,
}),
);
app.use(({ log }, res) => {
log({ status: 'noRoute' });
res.status(404).end();
});
app.use((e, { log }, res, next) => {
log({ status: 'routerError', error: e.message, stack: e.stack });
res.status(500).end();
});
app.listen(config.PORT || 3000);