From a8bbb95cc00c6f3486e117ab396b792804606b11 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 8 Jul 2020 13:02:18 -0400 Subject: [PATCH] fix for new clones with no dist folder --- web/src/html.js | 18 +++++++++--------- web/webpack.config.js | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/web/src/html.js b/web/src/html.js index de6384012..44870c89e 100644 --- a/web/src/html.js +++ b/web/src/html.js @@ -15,8 +15,6 @@ const { parseURI } = require('lbry-redux'); const fs = require('fs'); const path = require('path'); -let html = fs.readFileSync(path.join(__dirname, '/../dist/index.html'), 'utf8'); - function insertToHead(fullHtml, htmlToInsert) { return fullHtml.replace( /.*/s, @@ -155,8 +153,10 @@ async function getClaimFromChainquery(url) { } async function getHtml(ctx) { - const path = decodeURIComponent(ctx.path); - if (path.length === 0) { + const html = fs.readFileSync(path.join(__dirname, '/../dist/index.html'), 'utf8'); + const requestPath = decodeURIComponent(ctx.path); + + if (requestPath.length === 0) { const ogMetadata = buildBasicOgMetadata(); return insertToHead(html, ogMetadata); } @@ -164,7 +164,7 @@ async function getHtml(ctx) { const invitePath = `/$/${PAGES.INVITE}/`; const embedPath = `/$/${PAGES.EMBED}/`; - if (path.includes(invitePath)) { + if (requestPath.includes(invitePath)) { const inviteChannel = path.slice(invitePath.length).replace(/:/g, '#'); const inviteChannelUrl = `lbry://${inviteChannel}`; @@ -188,8 +188,8 @@ async function getHtml(ctx) { } } - if (path.includes(embedPath)) { - const claimUri = path.replace(embedPath, '').replace(/:/g, '#'); + if (requestPath.includes(embedPath)) { + const claimUri = requestPath.replace(embedPath, '').replace(/:/g, '#'); const claim = await getClaimFromChainquery(claimUri); if (claim) { @@ -200,8 +200,8 @@ async function getHtml(ctx) { return insertToHead(html); } - if (!path.includes('$')) { - const claimUri = path.slice(1).replace(/:/g, '#'); + if (!requestPath.includes('$')) { + const claimUri = requestPath.slice(1).replace(/:/g, '#'); const claim = await getClaimFromChainquery(claimUri); if (claim) { diff --git a/web/webpack.config.js b/web/webpack.config.js index 6dd0bd30c..f97bee414 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -6,7 +6,7 @@ const baseConfig = require('../webpack.base.config.js'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const { DefinePlugin, ProvidePlugin } = require('webpack'); const SentryWebpackPlugin = require('@sentry/webpack-plugin'); -// const { insertToHead, buildBasicOgMetadata } = require('./src/html'); +const { insertToHead, buildBasicOgMetadata } = require('./src/html'); const CUSTOM_ROOT = path.resolve(__dirname, '../custom/'); const STATIC_ROOT = path.resolve(__dirname, '../static/'); @@ -20,9 +20,9 @@ const copyWebpackCommands = [ { from: `${STATIC_ROOT}/index-web.html`, to: `${DIST_ROOT}/index.html`, - // transform(content, path) { - // return insertToHead(content.toString(), buildBasicOgMetadata()); - // }, + transform(content, path) { + return insertToHead(content.toString(), buildBasicOgMetadata()); + }, }, { from: `${STATIC_ROOT}/img/favicon.png`,