Skip to content

Commit

Permalink
Don't use / as webUrl, prefer NEXT_PUBLIC_WEB_URL or VERCEL_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Apr 9, 2021
1 parent 9238f23 commit a88e462
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ loadApiUrlFromEnv(envDevelopmentPath);
// Try to copy them across from existing values
envVarsToForward.forEach((envVar) => forwardToNext(envVar));

// NOTE: on Vercel, the value we get from VERCEL_URL for the WEB_URL will be
// missing the leading https://. If it's not there, add it now so the front-end
// can count on it always being an absolute URL.
process.env.NEXT_PUBLIC_WEB_URL = process.env.NEXT_PUBLIC_WEB_URL.startsWith('https://')
? process.env.NEXT_PUBLIC_WEB_URL
: `https://${process.env.NEXT_PUBLIC_WEB_URL}`;

// Indicate what the build values we're using are going to be.
envVarsToForward.forEach((envVar) =>
console.info(`Using NEXT_PUBLIC_${envVar}=${process.env[`NEXT_PUBLIC_${envVar}`]}`)
Expand Down
11 changes: 2 additions & 9 deletions src/web/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
// The URL to use when accessing the Telescope 1.0 backend APIs
const telescopeUrl = process.env.NEXT_PUBLIC_API_URL;

// The URL where our front-end is being hosted. If we don't have a URL,
// we use the current page's, and include a fallback of '/' for server-side rendering.
const webUrl =
// Either we have it defined via Docker env,
process.env.NEXT_PUBLIC_WEB_URL ||
// Or we're in Vercel, and the host provides it,
process.env.VERCEL_URL ||
// Or we need to make a guess.
(typeof window !== 'undefined' ? window.location.href : '/');
// The URL where our front-end is being hosted.
const webUrl = process.env.NEXT_PUBLIC_WEB_URL;

// The various Telescope 2.0 microservice endpoints we use
const imageServiceUrl = process.env.NEXT_PUBLIC_IMAGE_URL;
Expand Down
File renamed without changes.

0 comments on commit a88e462

Please sign in to comment.