lbry-desktop/web/index.js
infinite-persistence c6fb204d11 Skip checking DIST_ROOT twice
f0cd1592 did an additional call instead of replacement.

Aside: the 1 hour value only has effect in dev instances. For prod, CloudFlare seems to override that to 4 hours.
2022-01-05 09:00:28 -05:00

37 lines
1.1 KiB
JavaScript

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');
const redirectMiddleware = require('./middleware/redirect');
const cacheControlMiddleware = require('./middleware/cache-control');
const iframeDestroyerMiddleware = require('./middleware/iframe-destroyer');
const app = new Koa();
const DIST_ROOT = path.resolve(__dirname, 'dist');
app.proxy = true;
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
console.log('error: ', err);
ctx.status = err.status || 500;
ctx.body = err.message;
}
});
app.use(logger());
app.use(cacheControlMiddleware);
app.use(redirectMiddleware);
app.use(iframeDestroyerMiddleware);
// Check if the request url matches any assets inside of /dist
app.use(serve(DIST_ROOT, {
maxage: 3600000, // set a cache time of one hour, helpful for mobile dev
}));
app.use(router.routes());
app.listen(config.WEB_SERVER_PORT, () => `Server up at localhost:${config.WEB_SERVER_PORT}`);