// Setup CORS for the frontend'
.use('/trpc/*', async (c, next) => {
if (c.env.APP_NEXT_URL === undefined || c.env.APP_SPA_URL === undefined) {
console.log(
'APP_URL is not set. CORS errors may occur. Make sure the .dev.vars file is present at /packages/api/.dev.vars',
)
}
return await cors({
origin: (origin) => {
const appHost = new URL(c.env.APP_NEXT_URL).host
const spaHost = new URL(c.env.APP_SPA_URL).host
const preview = 'http://localhost:8788' // cloudflare pages preview
console.log('Origin: ', origin)
return origin.endsWith(appHost) || origin.endsWith(spaHost) || origin.endsWith(preview)
? origin
: c.env.APP_NEXT_URL
},
credentials: true, // https://trpc.io/docs/client/cors
allowMethods: ['GET', 'POST', 'OPTIONS'],
// https://hono.dev/middleware/builtin/cors#options
})(c, next)
})
// Setup CORS for the frontend'
.use('/trpc/*', async (c, next) => {
if (c.env.APP_NEXT_URL === undefined || c.env.APP_SPA_URL === undefined) {
console.log(
'APP_URL is not set. CORS errors may occur. Make sure the .dev.vars file is present at /packages/api/.dev.vars',
)
}
return await cors({
origin: (origin) => {
const appHost = new URL(c.env.APP_NEXT_URL).host
const spaHost = new URL(c.env.APP_SPA_URL).host
const preview = 'http://localhost:8788' // cloudflare pages preview
console.log('Origin: ', origin)
return origin.endsWith(appHost) || origin.endsWith(spaHost) || origin.endsWith(preview)
? origin
: c.env.APP_NEXT_URL
},
credentials: true, // https://trpc.io/docs/client/cors
allowMethods: ['GET', 'POST', 'OPTIONS'],
// https://hono.dev/middleware/builtin/cors#options
})(c, next)
})