lbry-desktop/lbrytv/index.js

27 lines
754 B
JavaScript
Raw Normal View History

2019-11-07 20:39:22 +01:00
const config = require('../config');
const path = require('path');
const Koa = require('koa');
const serve = require('koa-static');
const logger = require('koa-logger');
const router = require('./src/routes');
2019-11-11 19:19:31 +01:00
const redirectMiddleware = require('./middleware/redirect');
2019-11-07 20:39:22 +01:00
const app = new Koa();
const DIST_ROOT = path.resolve(__dirname, 'dist');
2019-11-11 19:24:22 +01:00
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
ctx.status = err.status || 500;
ctx.body = err.message;
}
});
2019-11-07 20:39:22 +01:00
app.use(logger());
2019-11-11 19:19:31 +01:00
app.use(redirectMiddleware);
2019-11-07 20:39:22 +01:00
app.use(serve(DIST_ROOT)); // Check if the request url matches any assets inside of /dist
app.use(router.routes());
app.listen(config.WEB_SERVER_PORT, () => `Server up at localhost:${config.WEB_SERVER_PORT}`);