Skip to content

Commit

Permalink
🧑‍💻 Automatically guess env URLs for Vercel preview deploy… (#1076)
Browse files Browse the repository at this point in the history
…ments

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced new URL processing logic to enhance compatibility with
Vercel preview environments.
- Improved handling of environment-specific URLs for authentication and
viewer services.

- **Enhancements**
- Streamlined environment variable management for more reliable
deployment configurations.

- **Documentation**
- Updated documentation to reflect new environment variable processing
functions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
baptisteArno authored Dec 5, 2023
1 parent 99c5aaf commit d89a1eb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
17 changes: 17 additions & 0 deletions apps/builder/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ const __filename = fileURLToPath(import.meta.url)

const __dirname = dirname(__filename)

const injectViewerUrlIfVercelPreview = (val) => {
if (
(val && typeof val === 'string' && val.length > 0) ||
process.env.VERCEL_ENV !== 'preview' ||
!process.env.VERCEL_BUILDER_PROJECT_NAME ||
!process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME
)
return
process.env.NEXT_PUBLIC_VIEWER_URL =
`https://${process.env.VERCEL_BRANCH_URL}`.replace(
process.env.VERCEL_BUILDER_PROJECT_NAME,
process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME
)
}

injectViewerUrlIfVercelPreview(process.env.NEXT_PUBLIC_VIEWER_URL)

configureRuntimeEnv()

/** @type {import('next').NextConfig} */
Expand Down
13 changes: 13 additions & 0 deletions apps/viewer/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ const __filename = fileURLToPath(import.meta.url)

const __dirname = dirname(__filename)

const injectViewerUrlIfVercelPreview = (val) => {
if (
(val && typeof val === 'string' && val.length > 0) ||
process.env.VERCEL_ENV !== 'preview' ||
!process.env.VERCEL_BUILDER_PROJECT_NAME ||
!process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME
)
return
process.env.NEXT_PUBLIC_VIEWER_URL = `https://${process.env.VERCEL_BRANCH_URL}`
}

injectViewerUrlIfVercelPreview(process.env.NEXT_PUBLIC_VIEWER_URL)

configureRuntimeEnv()

const landingPagePaths = [
Expand Down
53 changes: 48 additions & 5 deletions packages/env/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@ declare const window: {
__ENV?: any
}

const guessNextAuthUrlForVercelPreview = (val: unknown) => {
if (
(val && typeof val === 'string' && val.length > 0) ||
process.env.VERCEL_ENV !== 'preview' ||
!process.env.VERCEL_BUILDER_PROJECT_NAME ||
!process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME
)
return val
const isBuilder = (process.env.VERCEL_BRANCH_URL as string).includes(
process.env.VERCEL_BUILDER_PROJECT_NAME
)
if (isBuilder) return `https://${process.env.VERCEL_BRANCH_URL}`
return `https://${process.env.VERCEL_BRANCH_URL}`.replace(
process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME,
process.env.VERCEL_BUILDER_PROJECT_NAME
)
}

const guessViewerUrlForVercelPreview = (val: unknown) => {
if (
(val && typeof val === 'string' && val.length > 0) ||
process.env.VERCEL_ENV !== 'preview' ||
!process.env.VERCEL_BUILDER_PROJECT_NAME ||
!process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME
)
return val
const isViewer = (process.env.VERCEL_BRANCH_URL as string).includes(
process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME
)
if (isViewer) return `https://${process.env.VERCEL_BRANCH_URL}`
return `https://${process.env.VERCEL_BRANCH_URL}`.replace(
process.env.VERCEL_BUILDER_PROJECT_NAME,
process.env.NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME
)
}

const boolean = z.enum(['true', 'false']).transform((value) => value === 'true')

const baseEnv = {
Expand All @@ -16,7 +52,10 @@ const baseEnv = {
.url()
.refine((url) => url.startsWith('postgres') || url.startsWith('mysql')),
ENCRYPTION_SECRET: z.string().length(32),
NEXTAUTH_URL: z.string().url(),
NEXTAUTH_URL: z.preprocess(
guessNextAuthUrlForVercelPreview,
z.string().url()
),
DISABLE_SIGNUP: boolean.optional().default('false'),
ADMIN_EMAIL: z.string().email().optional(),
DEFAULT_WORKSPACE_PLAN: z
Expand All @@ -29,10 +68,13 @@ const baseEnv = {
},
client: {
NEXT_PUBLIC_E2E_TEST: boolean.optional(),
NEXT_PUBLIC_VIEWER_URL: z
.string()
.min(1)
.transform((string) => string.split(',')),
NEXT_PUBLIC_VIEWER_URL: z.preprocess(
guessViewerUrlForVercelPreview,
z
.string()
.min(1)
.transform((val) => val.split(','))
),
NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID: z.string().min(1).optional(),
NEXT_PUBLIC_BOT_FILE_UPLOAD_MAX_SIZE: z.coerce.number().optional(),
},
Expand Down Expand Up @@ -178,6 +220,7 @@ const vercelEnv = {
VERCEL_TOKEN: z.string().min(1).optional(),
VERCEL_TEAM_ID: z.string().min(1).optional(),
VERCEL_GIT_COMMIT_SHA: z.string().min(1).optional(),
VERCEL_BUILDER_PROJECT_NAME: z.string().min(1).optional(),
},
client: {
NEXT_PUBLIC_VERCEL_VIEWER_PROJECT_NAME: z.string().min(1).optional(),
Expand Down

3 comments on commit d89a1eb

@vercel
Copy link

@vercel vercel bot commented on d89a1eb Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d89a1eb Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on d89a1eb Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

bii.bj
1stop.au
houss.io
wasap.nl
x.cr8.ai
yobot.me
klujo.com
me.cr8.ai
sifuim.co
wachat.io
wassep.io
247987.com
8jours.top
ai.mprs.in
bee.cr8.ai
bot.aws.bj
bot.bbc.bj
signup.cr8.ai
start.taxt.co
thegymgame.it
theusm.com.br
turkey.cr8.ai
vhpage.cr8.ai
vitamyway.com
webwhats.chat
whatchat.site
www.wiccom.it
acessovip.shop
adsgrow.com.br
am.nigerias.io
an.nigerias.io
app.yvon.earth
ar.nigerias.io
bot.enreso.org
bot.mail2wa.me
bot.rslabs.pro
bot.share5.net
bot.wachap.app
bots.bng.tools
bots.bridge.ai
chad.gocto.com
chat.ftplay.me
chat.hayuri.id
chat.uprize.hu
chatgpt.lam.ee
chicken.cr8.ai
debitozero.com
drayumi.social
gollum.riku.ai
gsbulletin.com
journey.cr8.ai
kopibayane.com
panther.cr7.ai
panther.cr8.ai
pay.sifuim.com
penguin.cr8.ai
petaikorea.com
privetvplus.me
segredomeu.com
semaknilai.com
talk.gocare.io
ticketfute.com
unicorn.cr8.ai
whats-app.chat
whatsnaweb.com
apo.nigerias.io
viewer-v2-typebot-io.vercel.app
mdb.evento.equipeinterna.progenbr.com
bot.studiotecnicoimmobiliaremerelli.it
mdb.assessoria.boaventura.progenbr.com
mdb.assessoria.jtrebesqui.progenbr.com
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
mdb.assessoria.carreirinha.progenbr.com
chrome-os-inquiry-system.itschromeos.com
mdb.assessoria.paulomarques.progenbr.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
mdb.assessoria.qrcode.ademir.progenbr.com
mdb.assessoria.qrcode.arthur.progenbr.com
mdb.assessoria.qrcode.danilo.progenbr.com
mdb.assessoria.qrcode.marcao.progenbr.com
mdb.assessoria.qrcode.marcio.progenbr.com
mdb.assessoria.qrcode.aloisio.progenbr.com
mdb.assessoria.qrcode.girotto.progenbr.com
mdb.assessoria.qrcode.marinho.progenbr.com
mdb.assessoria.qrcode.rodrigo.progenbr.com
mdb.assessoria.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.desideri.progenbr.com
mdb.assessoria.qrcode.fernanda.progenbr.com
mdb.assessoria.qrcode.jbatista.progenbr.com
mdb.assessoria.qrcode.mauricio.progenbr.com
mdb.assessoria.fernanda.regional.progenbr.com
mdb.assessoria.qrcode.boaventura.progenbr.com
mdb.assessoria.qrcode.jtrebesqui.progenbr.com
mdb.assessoria.qrcode.carreirinha.progenbr.com
mdb.assessoria.qrcode.paulomarques.progenbr.com
mdb.assessoria.qrcode.carlosalexandre.progenbr.com
mdb.assessoria.qrcode.fernanda.regional.progenbr.com

Please sign in to comment.