From 1752b4026f669b158c58c5e2f367abce8d245145 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 11 Dec 2019 16:46:00 -0500 Subject: [PATCH] better webpack output structure and more robust path checking for cache-control --- lbrytv/middleware/cache-control.js | 24 +++++++++-- lbrytv/webpack.config.js | 10 ++--- static/font/font.css | 47 --------------------- static/font/{inter => v1}/300.woff | Bin static/font/{inter => v1}/300i.woff | Bin static/font/{inter => v1}/400.woff | Bin static/font/{inter => v1}/400i.woff | Bin static/font/{inter => v1}/700.woff | Bin static/font/{inter => v1}/700i.woff | Bin static/index-web.html | 62 ++++++++++++++++++++++++++-- webpack.base.config.js | 2 +- 11 files changed, 86 insertions(+), 59 deletions(-) delete mode 100644 static/font/font.css rename static/font/{inter => v1}/300.woff (100%) rename static/font/{inter => v1}/300i.woff (100%) rename static/font/{inter => v1}/400.woff (100%) rename static/font/{inter => v1}/400i.woff (100%) rename static/font/{inter => v1}/700.woff (100%) rename static/font/{inter => v1}/700i.woff (100%) diff --git a/lbrytv/middleware/cache-control.js b/lbrytv/middleware/cache-control.js index 6ff2373f7..c6bb7d809 100644 --- a/lbrytv/middleware/cache-control.js +++ b/lbrytv/middleware/cache-control.js @@ -1,12 +1,30 @@ -const THREE_MONTHS_IN_SECONDS = 7776000; +const SIX_MONTHS_IN_SECONDS = 15552000; + +const STATIC_ASSET_PATHS = [ + '/public/font/font-v1.css', + '/public/font/v1/300.woff', + '/public/font/v1/300i.woff', + '/public/font/v1/400.woff', + '/public/font/v1/400i.woff', + '/public/font/v1/700.woff', + '/public/font/v1/700i.woff', + '/public/favicon.png', + '/public/img/busy.gif', + '/public/img/gerbil-happy.png', + '/public/img/gerbil-sad.png', + '/public/img/placeholder.png', + '/public/img/thumbnail-broken.png', + '/public/img/thumbnail-missing.png', + '/public/img/total-background.png', +]; async function redirectMiddleware(ctx, next) { const { request: { url }, } = ctx; - if (url.includes('.png') || url.includes('font.css') || url.includes('.woff')) { - ctx.set('Cache-Control', `public, max-age=${THREE_MONTHS_IN_SECONDS}`); + if (STATIC_ASSET_PATHS.includes(url)) { + ctx.set('Cache-Control', `public, max-age=${SIX_MONTHS_IN_SECONDS}`); } return next(); diff --git a/lbrytv/webpack.config.js b/lbrytv/webpack.config.js index 81e51192e..4d44ab9c0 100644 --- a/lbrytv/webpack.config.js +++ b/lbrytv/webpack.config.js @@ -17,8 +17,8 @@ const webConfig = { }, output: { filename: '[name].js', - path: __dirname + '/dist/', - publicPath: '/', + path: __dirname + '/dist/public/', + publicPath: '/public/', }, devServer: { port: WEBPACK_WEB_PORT, @@ -62,15 +62,15 @@ const webConfig = { }, { from: `${STATIC_ROOT}/img/favicon.png`, - to: `${DIST_ROOT}/favicon.png`, + to: `${DIST_ROOT}/public/favicon.png`, }, { from: `${STATIC_ROOT}/img/og.png`, - to: `${DIST_ROOT}/og.png`, + to: `${DIST_ROOT}/public/og.png`, }, { from: `${STATIC_ROOT}/font/`, - to: `${DIST_ROOT}/font/`, + to: `${DIST_ROOT}/public/font/`, }, ]), new DefinePlugin({ diff --git a/static/font/font.css b/static/font/font.css deleted file mode 100644 index 9bd25afd5..000000000 --- a/static/font/font.css +++ /dev/null @@ -1,47 +0,0 @@ -@font-face { - font-family: 'Inter'; - font-style: normal; - font-weight: 300; - font-display: swap; - src: url('/font/inter/300.woff') format('woff'); -} - -@font-face { - font-family: 'Inter'; - font-style: italic; - font-weight: 300; - font-display: swap; - src: url('/font/inter/300i.woff') format('woff'); -} - -@font-face { - font-family: 'Inter'; - font-style: normal; - font-weight: 400; - font-display: swap; - src: url('/font/inter/400.woff') format('woff'); -} - -@font-face { - font-family: 'Inter'; - font-style: italic; - font-weight: 400; - font-display: swap; - src: url('/font/inter/400i.woff') format('woff'); -} - -@font-face { - font-family: 'Inter'; - font-style: normal; - font-weight: 700; - font-display: swap; - src: url('/font/inter/700.woff') format('woff'); -} - -@font-face { - font-family: 'Inter'; - font-style: italic; - font-weight: 700; - font-display: swap; - src: url('/font/inter/700i.woff') format('woff'); -} diff --git a/static/font/inter/300.woff b/static/font/v1/300.woff similarity index 100% rename from static/font/inter/300.woff rename to static/font/v1/300.woff diff --git a/static/font/inter/300i.woff b/static/font/v1/300i.woff similarity index 100% rename from static/font/inter/300i.woff rename to static/font/v1/300i.woff diff --git a/static/font/inter/400.woff b/static/font/v1/400.woff similarity index 100% rename from static/font/inter/400.woff rename to static/font/v1/400.woff diff --git a/static/font/inter/400i.woff b/static/font/v1/400i.woff similarity index 100% rename from static/font/inter/400i.woff rename to static/font/v1/400i.woff diff --git a/static/font/inter/700.woff b/static/font/v1/700.woff similarity index 100% rename from static/font/inter/700.woff rename to static/font/v1/700.woff diff --git a/static/font/inter/700i.woff b/static/font/v1/700i.woff similarity index 100% rename from static/font/inter/700i.woff rename to static/font/v1/700i.woff diff --git a/static/index-web.html b/static/index-web.html index f72ed08b0..5c535da93 100644 --- a/static/index-web.html +++ b/static/index-web.html @@ -2,9 +2,65 @@ - - - + + + + + + + + + + + lbry.tv diff --git a/webpack.base.config.js b/webpack.base.config.js index f1d9414a0..c913b6b23 100644 --- a/webpack.base.config.js +++ b/webpack.base.config.js @@ -47,7 +47,7 @@ let baseConfig = { use: { loader: 'file-loader', options: { - outputPath: 'static/img', + outputPath: 'img/', name: '[name].[ext]', }, },