fetch-dht/index.js

41 lines
911 B
JavaScript
Raw Normal View History

2020-04-12 21:33:32 +00:00
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);