fix redirect middleware

This commit is contained in:
Sean Yesmunt 2019-11-11 13:19:31 -05:00
parent 3f2de50368
commit dbe4511c62
3 changed files with 9 additions and 6 deletions

View file

@ -4,11 +4,13 @@ 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 app = new Koa();
const DIST_ROOT = path.resolve(__dirname, 'dist');
app.use(logger());
app.use(redirectMiddleware);
app.use(serve(DIST_ROOT)); // Check if the request url matches any assets inside of /dist
app.use(router.routes());

View file

@ -6,7 +6,7 @@ async function redirectMiddleware(ctx, next) {
const path = ctx.path;
const url = ctx.url;
if (urlPath.endsWith('/') && urlPath.length > 1) {
if (path.endsWith('/') && path.length > 1) {
ctx.redirect(url.replace(/\/$/, ''));
return;
}

View file

@ -1,14 +1,15 @@
const { getHtml } = require('./html');
const { generateStreamUrl } = require('../../ui/util/lbrytv');
const { LBRY_TV_API } = require('../../config');
const Router = require('@koa/router');
const send = require('koa-send');
const router = new Router();
router.get(`/embed/:claimName/:claimId`, async ctx => {
const { claimName, claimId } = ctx.params;
const streamUrl = generateStreamUrl(claimName, claimName);
ctx.redirect = streamUrl;
});
// TODO
// router.get(`/embed/:claimName/:claimId`, async ctx => {
// Proxy request through lbrytv
// });
router.get('*', async ctx => {
const html = await getHtml(ctx);