W
Wasp-lang3mo ago
Sam79

Why doesn't console.log output anything to terminal?

I am trying to debug cors middleware setup. In main.wasp I have:
server: {
setupFn: import setup from "@src/ServerSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/ServerSetup"
}
server: {
setupFn: import setup from "@src/ServerSetup",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/ServerSetup"
}
In ServerSetup.ts for testing I have:
export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
console.log("nothing is shown in the console log")
middlewareConfig.set('cors', cors({ origin: [config.frontendUrl] }))
return middlewareConfig
}
export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
console.log("nothing is shown in the console log")
middlewareConfig.set('cors', cors({ origin: [config.frontendUrl] }))
return middlewareConfig
}
Since I see no output it looks like serverMiddlewareFn is never called.
3 Replies
kapa.ai
kapa.ai3mo ago
Hi @Sam79. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided, it seems like you have correctly set up the serverMiddlewareFn in your ServerSetup.ts file and correctly referenced it in your main.wasp file. However, it's important to note that the serverMiddlewareFn is a global middleware configuration function that modifies the middleware stack for all operations and APIs. This means that it will only be called when an operation or API request is made that goes through the middleware stack. If you're not seeing any output from the console.log statement in your serverMiddlewareFn, it could be because no such requests are being made, or there might be an error occurring before the middleware function gets called. To debug this, you could try making a request to your server that should go through the middleware stack and see if the console.log statement gets executed then. If you're still not seeing any output, there might be an error occurring elsewhere in your code that's preventing the middleware function from being called. You could try checking the server logs for any error messages or exceptions that might give you a clue as to what's going wrong. If you're still having trouble, you might want to consider opening an issue on the Wasp GitHub page (https://github.com/wasp-lang/wasp/issues) to get help from the Wasp community. Sources: - Server Config > Middleware Config Function (https://wasp-lang.dev/docs/project/server-config#middleware-config-function) - Advanced > Configuring Middleware > 1. Customize Global Middleware (https://wasp-lang.dev/docs/advanced/middleware-config#1-customize-global-middleware) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Sam79, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho3mo ago
Where are you looking for the logs? In the terminal or in the browser console?
miho
miho3mo ago
I did this:
app consolelog {
wasp: {
version: "^0.14.0"
},
title: "consolelog",
server: {
middlewareConfigFn: import { serverMiddlewareFn } from "@src/setup"
}
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
component: import { MainPage } from "@src/MainPage"
}
app consolelog {
wasp: {
version: "^0.14.0"
},
title: "consolelog",
server: {
middlewareConfigFn: import { serverMiddlewareFn } from "@src/setup"
}
}

route RootRoute { path: "/", to: MainPage }
page MainPage {
component: import { MainPage } from "@src/MainPage"
}
and
import { MiddlewareConfigFn } from 'wasp/server'

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
console.log("nothing is shown in the console log")
return middlewareConfig
}
import { MiddlewareConfigFn } from 'wasp/server'

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
console.log("nothing is shown in the console log")
return middlewareConfig
}
and here's the output:
No description
Want results from more Discord servers?
Add your server