Skip to content

Commit

Permalink
Hardcode Vercel URL
Browse files Browse the repository at this point in the history
  • Loading branch information
kmjennison committed Jul 20, 2022
1 parent 30be0c6 commit 3e5561c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ COOKIE_SECURE_SAME_SITE_NONE=false

########## URL/Path Configuration ##########

# For local development only. This is set by Vercel in deploys.
NEXT_PUBLIC_VERCEL_URL=http://localhost:3001/

# Note that the base path is also hardcoded in vercel.json and
# next.config.js.
NEXT_PUBLIC_URLS_BASE_PATH=/newtab
Expand Down
7 changes: 3 additions & 4 deletions __test__/next.config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ jest.mock('@sentry/webpack-plugin')
jest.mock('@zeit/next-source-maps', () => () => (config) => config)

beforeEach(() => {
process.env.NEXT_PUBLIC_VERCEL_URL = 'tab-abc123-gladly-team.vercel.app'
process.env.NEXT_PUBLIC_URLS_BASE_PATH = '/newtab'
})

Expand All @@ -30,15 +29,15 @@ describe('Next.js config', () => {
expect.assertions(1)
const config = require('../next.config')
expect(config.workboxOpts.runtimeCaching[0].urlPattern).toEqual(
/tab-abc123-gladly-team.vercel.app\/newtab.*|https:\/\/prod-tab2017-media.gladly.io\/.*|https:\/\/dev-tab2017-media.gladly.io\/.*|https:\/\/dev-tab2017.gladly.io\/newtab\/.*|https:\/\/tab.gladly.io\/newtab\/.*/
/.*-gladly-team.vercel.app\/newtab.*|https:\/\/prod-tab2017-media.gladly.io\/.*|https:\/\/dev-tab2017-media.gladly.io\/.*|https:\/\/dev-tab2017.gladly.io\/newtab\/.*|https:\/\/tab.gladly.io\/newtab\/.*/
)
})

it('throws if the NEXT_PUBLIC_VERCEL_URL environment variable is not set', () => {
it('does not throw if the NEXT_PUBLIC_VERCEL_URL environment variable is not set', () => {
expect.assertions(1)
delete process.env.NEXT_PUBLIC_VERCEL_URL
expect(() => {
require('../next.config')
}).toThrow(new Error('Env var "NEXT_PUBLIC_VERCEL_URL" is required.'))
}).not.toThrow()
})
})
8 changes: 2 additions & 6 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@ const withSourceMaps = require('@zeit/next-source-maps')({
})

const basePath = process.env.NEXT_PUBLIC_URLS_BASE_PATH || ''
const url = process.env.NEXT_PUBLIC_VERCEL_URL
if (!url) {
throw new Error('Env var "NEXT_PUBLIC_VERCEL_URL" is required.')
}

const generalizedVercelDomain = '.*-gladly-team.vercel.app'
const devAssetsRegex = 'https://prod-tab2017-media.gladly.io/.*'
const prodAssetsRegex = 'https://dev-tab2017-media.gladly.io/.*'
const devCloudFrontRegex = 'https://dev-tab2017.gladly.io/newtab/.*'
const prodCloudFrontRegex = 'https://tab.gladly.io/newtab/.*'

const cachingRegex = new RegExp(
`${url}${basePath}.*|${devAssetsRegex}|${prodAssetsRegex}|${devCloudFrontRegex}|${prodCloudFrontRegex}`
`${generalizedVercelDomain}${basePath}.*|${devAssetsRegex}|${prodAssetsRegex}|${devCloudFrontRegex}|${prodCloudFrontRegex}`
)

// Use the SentryWebpack plugin to upload the source maps during build.
Expand Down

0 comments on commit 3e5561c

Please sign in to comment.