lbry-desktop/web/src/routes.js
jessop e3c2919373 rename lbrytv to web
language and API consts

improve customization
custom homepages
get config from .env.default
custom title and logo

small changes

add pinned item to sidebar

rebase?
2020-05-25 17:21:02 -04:00

34 lines
900 B
JavaScript

const { getHtml } = require('./html');
const { generateStreamUrl } = require('../../ui/util/web');
const fetch = require('node-fetch');
const Router = require('@koa/router');
// So any code from 'lbry-redux'/'lbryinc' that uses `fetch` can be run on the server
global.fetch = fetch;
const router = new Router();
function getStreamUrl(ctx) {
const { claimName, claimId } = ctx.params;
const streamUrl = generateStreamUrl(claimName, claimId);
return streamUrl;
}
router.get(`/$/download/:claimName/:claimId`, async ctx => {
const streamUrl = getStreamUrl(ctx);
const downloadUrl = `${streamUrl}?download=1`;
ctx.redirect(downloadUrl);
});
router.get(`/$/stream/:claimName/:claimId`, async ctx => {
const streamUrl = getStreamUrl(ctx);
ctx.redirect(streamUrl);
});
router.get('*', async ctx => {
const html = await getHtml(ctx);
ctx.body = html;
});
module.exports = router;