Chyz/improve preview workers (#6802)

* fix: branch url in comment

* fix: use sub not small

* de-hardcode siteUrl

* simplify request hook

* nuxt server plugin?

* pull directly from worker + 2 tables

* debug

* undebug

* single preview worker?

* use pr number instead of name because pr names tend to be long + can be changed

* prepr

---------

Co-authored-by: Calum H. (IMB11) <contact@cal.engineer>
Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
This commit is contained in:
chyz
2026-07-22 20:58:14 +00:00
committed by GitHub
co-authored by Calum H. Prospector
parent 56ff97ee6f
commit dce20777ef
4 changed files with 152 additions and 47 deletions
+1 -5
View File
@@ -364,11 +364,7 @@ function getFeatureFlagOverrides() {
function getDomain() {
if (process.env.NODE_ENV === 'production') {
// @ts-ignore
if (process.env.CF_PAGES_URL || globalThis.CF_PAGES_URL) {
// @ts-ignore
return process.env.CF_PAGES_URL ?? globalThis.CF_PAGES_URL
} else if (process.env.HEROKU_APP_NAME) {
if (process.env.HEROKU_APP_NAME) {
return `https://${process.env.HEROKU_APP_NAME}.herokuapp.com`
} else if (process.env.VERCEL_URL) {
return `https://${process.env.VERCEL_URL}`
@@ -0,0 +1,20 @@
export default defineEventHandler(async (event) => {
try {
const mod = 'cloudflare:workers'
const { env } = await import(/* @vite-ignore */ mod)
const cfEnv = env as any
const config = useRuntimeConfig(event)
if (cfEnv.CF_PAGES_URL) config.public.siteUrl = cfEnv.CF_PAGES_URL
if (cfEnv.BROWSER_BASE_URL) config.public.apiBaseUrl = cfEnv.BROWSER_BASE_URL
if (cfEnv.BASE_URL) config.apiBaseUrl = cfEnv.BASE_URL
if (cfEnv.PYRO_BASE_URL) {
config.public.pyroBaseUrl = cfEnv.PYRO_BASE_URL
config.pyroBaseUrl = cfEnv.PYRO_BASE_URL
}
if (cfEnv.STRIPE_PUBLISHABLE_KEY)
config.public.stripePublishableKey = cfEnv.STRIPE_PUBLISHABLE_KEY
} catch {
/* empty */
}
})