diff --git a/lbrytv/index.js b/lbrytv/index.js index 148cf35a1..487c09d80 100644 --- a/lbrytv/index.js +++ b/lbrytv/index.js @@ -10,6 +10,8 @@ const cacheControlMiddleware = require('./middleware/cache-control'); const app = new Koa(); const DIST_ROOT = path.resolve(__dirname, 'dist'); +app.proxy = true; + app.use(async (ctx, next) => { try { await next(); diff --git a/lbrytv/src/routes.js b/lbrytv/src/routes.js index b0fb9ce92..1f602ce37 100644 --- a/lbrytv/src/routes.js +++ b/lbrytv/src/routes.js @@ -31,8 +31,8 @@ function getSupportedCDN(continent) { } } -async function fetchContinentCookie() { - return Lbryio.call('locale', 'get', {}, 'post').then(result => { +async function fetchContinentCookie(ip) { + return Lbryio.call('locale', 'get', { ip }, 'post').then(result => { const userContinent = getSupportedCDN(result.continent); return userContinent; }); @@ -51,9 +51,13 @@ router.get(`/$/stream/:claimName/:claimId`, async ctx => { router.get('*', async ctx => { const hasContinentCookie = ctx.cookies.get(CONTINENT_COOKIE); + const ip = ctx.ip; + if (!hasContinentCookie) { - const continentValue = await fetchContinentCookie(); - ctx.cookies.set(CONTINENT_COOKIE, continentValue, { httpOnly: false }); + try { + const continentValue = await fetchContinentCookie(ip); + ctx.cookies.set(CONTINENT_COOKIE, continentValue, { httpOnly: false }); + } catch (e) {} } const html = await getHtml(ctx); ctx.body = html;