Skip to content

Commit

Permalink
Cleaner webpack config
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeredwolf committed Aug 17, 2022
1 parent 58e1f08 commit 8f31ae0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 45 deletions.
12 changes: 8 additions & 4 deletions src/server.ts
Expand Up @@ -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');
Expand Down Expand Up @@ -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
);
}
};

Expand Down Expand Up @@ -316,8 +319,9 @@ const sentryWrapper = async (event: FetchEvent, test = false): Promise<void> =>
/* 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,
Expand Down
62 changes: 21 additions & 41 deletions webpack.config.js
Expand Up @@ -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}'`
})
];

Expand All @@ -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: {
Expand All @@ -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 }
}
]
}
Expand Down

0 comments on commit 8f31ae0

Please sign in to comment.