From 8f31ae0609a8a3ff5af8f2d6efe4404a3cf9d322 Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Wed, 17 Aug 2022 04:58:19 -0400 Subject: [PATCH] Cleaner webpack config --- src/server.ts | 12 ++++++--- webpack.config.js | 62 ++++++++++++++++------------------------------- 2 files changed, 29 insertions(+), 45 deletions(-) diff --git a/src/server.ts b/src/server.ts index 9543e702..76c2cb22 100644 --- a/src/server.ts +++ b/src/server.ts @@ -88,7 +88,7 @@ const statusRequest = async ( flags, language ); - + /* Complete responses are normally sent just by errors. Normal embeds send a `text` value. */ if (statusResponse.response) { console.log('handleStatus sent response'); @@ -120,7 +120,10 @@ const statusRequest = async ( /* A human has clicked a fxtwitter.com/:screen_name/status/:id link! Obviously we just need to redirect to the Tweet directly.*/ console.log('Matched human UA', userAgent); - return Response.redirect(`${Constants.TWITTER_ROOT}/${handle}/status/${id?.match(/\d{2,20}/)?.[0]}`, 302); + return Response.redirect( + `${Constants.TWITTER_ROOT}/${handle}/status/${id?.match(/\d{2,20}/)?.[0]}`, + 302 + ); } }; @@ -316,8 +319,9 @@ const sentryWrapper = async (event: FetchEvent, test = false): Promise => /* We use Toucan for Sentry. Toucan is a Sentry SDK designed for Cloudflare Workers / DOs */ sentry = new Toucan({ dsn: SENTRY_DSN, - context: event, /* Includes 'waitUntil', which is essential for Sentry logs to be delivered. - Also includes 'request' -- no need to set it separately. */ + context: event, + /* event includes 'waitUntil', which is essential for Sentry logs to be delivered. + Also includes 'request' -- no need to set it separately. */ allowedHeaders: /(.*)/, allowedSearchParams: /(.*)/, release: RELEASE_NAME, diff --git a/webpack.config.js b/webpack.config.js index 36dd7177..bb4bc606 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,42 +17,28 @@ const releaseName = `fixtweet-${gitBranch}-${gitCommit}-${new Date() require('dotenv').config(); +let envVariables = [ + 'BRANDING_NAME', + 'BRANDING_NAME_DISCORD', + 'DIRECT_MEDIA_DOMAINS', + 'HOST_URL', + 'REDIRECT_URL', + 'EMBED_URL', + 'MOSAIC_DOMAIN_LIST', + 'API_HOST_LIST', + 'SENTRY_DSN', + 'DEPRECATED_DOMAIN_LIST', + 'DEPRECATED_DOMAIN_EPOCH' +]; + let plugins = [ - new webpack.DefinePlugin({ - BRANDING_NAME: `'${process.env.BRANDING_NAME}'` - }), - new webpack.DefinePlugin({ - BRANDING_NAME_DISCORD: `'${process.env.BRANDING_NAME_DISCORD}'` - }), - new webpack.DefinePlugin({ - DIRECT_MEDIA_DOMAINS: `'${process.env.DIRECT_MEDIA_DOMAINS}'` - }), - new webpack.DefinePlugin({ - HOST_URL: `'${process.env.HOST_URL}'` - }), - new webpack.DefinePlugin({ - REDIRECT_URL: `'${process.env.REDIRECT_URL}'` - }), - new webpack.DefinePlugin({ - EMBED_URL: `'${process.env.EMBED_URL}'` - }), - new webpack.DefinePlugin({ - MOSAIC_DOMAIN_LIST: `'${process.env.MOSAIC_DOMAIN_LIST}'` - }), - new webpack.DefinePlugin({ - API_HOST_LIST: `'${process.env.API_HOST_LIST}'` - }), - new webpack.DefinePlugin({ - SENTRY_DSN: `'${process.env.SENTRY_DSN}'` + ...envVariables.map(envVar => { + return new webpack.DefinePlugin({ + [envVar]: JSON.stringify(process.env[envVar]) + }); }), new webpack.DefinePlugin({ RELEASE_NAME: `'${releaseName}'` - }), - new webpack.DefinePlugin({ - DEPRECATED_DOMAIN_LIST: `'${process.env.DEPRECATED_DOMAIN_LIST}'` - }), - new webpack.DefinePlugin({ - DEPRECATED_DOMAIN_EPOCH: `'${process.env.DEPRECATED_DOMAIN_EPOCH}'` }) ]; @@ -69,9 +55,7 @@ if (process.env.SENTRY_AUTH_TOKEN) { } module.exports = { - entry: { - worker: './src/server.ts' - }, + entry: { worker: './src/server.ts' }, target: 'webworker', devtool: 'source-map', output: { @@ -84,17 +68,13 @@ module.exports = { fallback: { util: false } }, plugins: plugins, - optimization: { - mangleExports: 'size' - }, + optimization: { mangleExports: false }, module: { rules: [ { test: /\.tsx?$/, loader: 'ts-loader', - options: { - transpileOnly: true - } + options: { transpileOnly: true } } ] }