Fix local prod builds assuming CDN (#814)
* Fix local prod builds assuming CDN Prod builds assumed that we're running in an AWS environment and use a CDN. This commit changes that. Now, if the AWS way to fetch the commit failed _and_ the normal git command fails and only if, we assume we're running the prod build locally and don't configure the CDN. * Fix path to app_version_manifest.json Was autoformatted by linter. Probably before I added eslint-next-disable-line above.
This commit is contained in:
parent
894a73d713
commit
a4e84e7a2e
@ -2,7 +2,7 @@ const { withPlausibleProxy } = require('next-plausible')
|
|||||||
const { InjectManifest } = require('workbox-webpack-plugin')
|
const { InjectManifest } = require('workbox-webpack-plugin')
|
||||||
const { generatePrecacheManifest } = require('./sw/build.js')
|
const { generatePrecacheManifest } = require('./sw/build.js')
|
||||||
|
|
||||||
const isProd = process.env.NODE_ENV === 'production'
|
let isProd = process.env.NODE_ENV === 'production'
|
||||||
const corsHeaders = [
|
const corsHeaders = [
|
||||||
{
|
{
|
||||||
key: 'Access-Control-Allow-Origin',
|
key: 'Access-Control-Allow-Origin',
|
||||||
@ -18,13 +18,27 @@ const noCacheHeader = {
|
|||||||
value: 'no-cache, max-age=0, must-revalidate'
|
value: 'no-cache, max-age=0, must-revalidate'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getGitCommit = (env) => {
|
||||||
|
return env === 'aws'
|
||||||
|
// XXX this fragile ... eb could change the version label location ... it also require we set the label on deploy
|
||||||
|
// eslint-disable-next-line
|
||||||
|
? Object.keys(require('/opt/elasticbeanstalk/deployment/app_version_manifest.json').RuntimeSources['stacker.news'])[0].slice(0, 6)
|
||||||
|
: require('child_process').execSync('git rev-parse HEAD').toString().slice(0, 6)
|
||||||
|
}
|
||||||
|
|
||||||
let commitHash
|
let commitHash
|
||||||
try {
|
try {
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
// XXX this fragile ... eb could change the version label location ... it also require we set the label on deploy
|
try {
|
||||||
commitHash = Object.keys(require('/opt/elasticbeanstalk/deployment/app_version_manifest.json').RuntimeSources['stacker.news'])[0].slice(0, 6) // eslint-disable-line
|
commitHash = getGitCommit('aws')
|
||||||
|
} catch (e) {
|
||||||
|
// maybe we're running prod build locally
|
||||||
|
commitHash = getGitCommit()
|
||||||
|
// if above line worked, we're running locally and should not use prod config which configurates CDN
|
||||||
|
isProd = false
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
commitHash = require('child_process').execSync('git rev-parse HEAD').toString().slice(0, 6)
|
commitHash = getGitCommit()
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('could not get commit hash with `git rev-parse HEAD` ... using 0000')
|
console.log('could not get commit hash with `git rev-parse HEAD` ... using 0000')
|
||||||
@ -43,7 +57,7 @@ module.exports = withPlausibleProxy()({
|
|||||||
},
|
},
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
productionBrowserSourceMaps: true,
|
productionBrowserSourceMaps: true,
|
||||||
generateBuildId: isProd ? async () => commitHash : undefined,
|
generateBuildId: commitHash ? async () => commitHash : undefined,
|
||||||
// Use the CDN in production and localhost for development.
|
// Use the CDN in production and localhost for development.
|
||||||
assetPrefix: isProd ? 'https://a.stacker.news' : undefined,
|
assetPrefix: isProd ? 'https://a.stacker.news' : undefined,
|
||||||
crossOrigin: isProd ? 'anonymous' : undefined,
|
crossOrigin: isProd ? 'anonymous' : undefined,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user