From 8839bb08dbcd51a985c639e54fe473977bda8203 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Tue, 26 Nov 2019 14:04:28 -0500 Subject: [PATCH] better open.lbry.com redirect handling for lbry.tv --- config.js | 2 +- lbrytv/middleware/redirect.js | 22 ++++++++++++--- ui/constants/pages.js | 50 +++++++++++++++++------------------ ui/index.jsx | 2 ++ yarn.lock | 10 +++---- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/config.js b/config.js index e3f1ef76e..5dcdaf381 100644 --- a/config.js +++ b/config.js @@ -1,7 +1,7 @@ const config = { WEBPACK_WEB_PORT: 9090, WEBPACK_ELECTRON_PORT: 9091, - WEB_SERVER_PORT: 1337, + WEB_SERVER_PORT: 80, DOMAIN: 'lbry.tv', URL: 'https://lbry.tv', SITE_TITLE: 'lbry.tv', diff --git a/lbrytv/middleware/redirect.js b/lbrytv/middleware/redirect.js index 2c09af97b..ae6606897 100644 --- a/lbrytv/middleware/redirect.js +++ b/lbrytv/middleware/redirect.js @@ -1,5 +1,5 @@ const config = require('../../config'); -const redirectHosts = ['open.lbry.com']; +const PAGES = require('../../ui/constants/pages'); async function redirectMiddleware(ctx, next) { const requestHost = ctx.host; @@ -16,8 +16,24 @@ async function redirectMiddleware(ctx, next) { return; } - if (redirectHosts.includes(requestHost)) { - const redirectUrl = config.URL + path; + if (requestHost === 'open.lbry.com') { + let redirectUrl = config.URL; + const openQuery = '?src=open'; + const matches = /(\/\?)([a-z]*)(.*)/.exec(url); + + if (matches && matches.length) { + [, , page, queryString] = matches; + + // This is a lbry app page. Make sure to add the leading `/$/` + if (page && Object.values(PAGES).includes(page)) { + redirectUrl += '/$/' + page; + } + + redirectUrl += openQuery + queryString; + } else { + redirectUrl += path + openQuery; + } + ctx.redirect(redirectUrl); return; } diff --git a/ui/constants/pages.js b/ui/constants/pages.js index f5d89f7ec..97f92ccac 100644 --- a/ui/constants/pages.js +++ b/ui/constants/pages.js @@ -1,25 +1,25 @@ -export const AUTH = 'signin'; -export const AUTH_VERIFY = 'verify'; -export const BACKUP = 'backup'; -export const CHANNEL = 'channel'; -export const DISCOVER = 'discover'; -export const DOWNLOADED = 'downloaded'; -export const HELP = 'help'; -export const LIBRARY = 'library'; -export const INVITE = 'invite'; -export const PUBLISH = 'publish'; -export const PUBLISHED = 'published'; -export const GET_CREDITS = 'getcredits'; -export const REPORT = 'report'; -export const REWARDS = 'rewards'; -export const SEND = 'send'; -export const SETTINGS = 'settings'; -export const SHOW = 'show'; -export const ACCOUNT = 'account'; -export const FOLLOWING = 'following'; -export const SEARCH = 'search'; -export const TRANSACTIONS = 'transactions'; -export const TAGS = 'tags'; -export const WALLET = 'wallet'; -export const BLOCKED = 'blocked'; -export const CHANNELS = 'channels'; +exports.AUTH = 'signin'; +exports.AUTH_VERIFY = 'verify'; +exports.BACKUP = 'backup'; +exports.CHANNEL = 'channel'; +exports.DISCOVER = 'discover'; +exports.DOWNLOADED = 'downloaded'; +exports.HELP = 'help'; +exports.LIBRARY = 'library'; +exports.INVITE = 'invite'; +exports.PUBLISH = 'publish'; +exports.PUBLISHED = 'published'; +exports.GET_CREDITS = 'getcredits'; +exports.REPORT = 'report'; +exports.REWARDS = 'rewards'; +exports.SEND = 'send'; +exports.SETTINGS = 'settings'; +exports.SHOW = 'show'; +exports.ACCOUNT = 'account'; +exports.FOLLOWING = 'following'; +exports.SEARCH = 'search'; +exports.TRANSACTIONS = 'transactions'; +exports.TAGS = 'tags'; +exports.WALLET = 'wallet'; +exports.BLOCKED = 'blocked'; +exports.CHANNELS = 'channels'; diff --git a/ui/index.jsx b/ui/index.jsx index 52db88278..7dab9afc6 100644 --- a/ui/index.jsx +++ b/ui/index.jsx @@ -1,3 +1,5 @@ +import 'babel-polyfill'; + import ErrorBoundary from 'component/errorBoundary'; import App from 'component/app'; import SnackBar from 'component/snackBar'; diff --git a/yarn.lock b/yarn.lock index 0bb682447..26cc143d2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8118,10 +8118,10 @@ node-releases@^1.1.38: dependencies: semver "^6.3.0" -node-sass@^4.11.0: - version "4.12.0" - resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.12.0.tgz#0914f531932380114a30cc5fa4fa63233a25f017" - integrity sha512-A1Iv4oN+Iel6EPv77/HddXErL2a+gZ4uBeZUy+a8O35CFYTXhgA8MgLCWBtwpGZdCvTvQ9d+bQxX/QC36GDPpQ== +node-sass@^4.13.0: + version "4.13.0" + resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.13.0.tgz#b647288babdd6a1cb726de4545516b31f90da066" + integrity sha512-W1XBrvoJ1dy7VsvTAS5q1V45lREbTlZQqFbiHb3R3OTTCma0XBtuG6xZ6Z4506nR4lmHPTqVRwxT6KgtWC97CA== dependencies: async-foreach "^0.1.3" chalk "^1.1.1" @@ -8130,7 +8130,7 @@ node-sass@^4.11.0: get-stdin "^4.0.1" glob "^7.0.3" in-publish "^2.0.0" - lodash "^4.17.11" + lodash "^4.17.15" meow "^3.7.0" mkdirp "^0.5.1" nan "^2.13.2"