CupOfJoe
WWasp
•Created by CupOfJoe on 1/23/2025 in #đŸ™‹questions
CORS middleware wasp generate bug
Was having a CORS issue so I did what one of the guides said and added.
// main.wasp
server: {
setupFn: import setup from "@src/serverSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup"
},
//src/serverSetup
import cors from 'cors'
import { config } from 'wasp/server'
export const serverMiddlewareFn = (middlewareConfig: any) => {
middlewareConfig.set('cors', cors({ origin: [config.frontendUrl, 'https:rehouzd.com'] }))
return middlewareConfig
}
However, when recompiling wasp gave this issue:
[!] RollupError: src/server.ts (6:7): "default" is not exported by "../../../src/serverSetup.ts", imported by "src/server.ts".
So I went into the generated:
/app/.wasp/out/server/src/server.ts
and noticed it was importing like this:
import setup from '../../../../src/serverSetup'
To fix the issue I updated my serverSetup to have a default export and it fixed the issue:
import cors from 'cors'
import { config } from 'wasp/server'
const serverMiddlewareFn = (middlewareConfig: any) => {
middlewareConfig.set('cors', cors({ origin: [config.frontendUrl, 'https:rehouzd.com'] }))
return middlewareConfig
}
export default serverMiddlewareFn;
Looks like at least for this file generation wasp was expecting default export syntax instead of just export const. Feel like this could be an issue for others. Thoughts?8 replies