W
Wasp2mo ago
Hastur

Remove/replace the server's Hello world response?

Hello, I would like to know if it is possible to remove the Hello World returned message when visiting the server url. The line in question:
router.get('/', middleware, function (_req, res, _next) {
res.json('Hello world')
})
router.get('/', middleware, function (_req, res, _next) {
res.json('Hello world')
})
is generated on build so it seems I cannot modify it. Thank you.
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @Hastur. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to modify or replace the default "Hello world" response from the server in Wasp. You can do this by using the server configuration options provided by Wasp. Here's how you can achieve this: 1. You can use the setupFn in the server field of your app declaration to add a custom route. This will allow you to override the default behavior. 2. In your main.wasp file, add the following configuration:
app MyApp {
title: "My app",
// ...
server: {
setupFn: import { mySetupFunction } from "@src/myServerSetupCode.js"
}
}
app MyApp {
title: "My app",
// ...
server: {
setupFn: import { mySetupFunction } from "@src/myServerSetupCode.js"
}
}
3. Then, in your src/myServerSetupCode.js file, you can add a custom route:
export const mySetupFunction = async ({ app }) => {
addCustomRoute(app)
}

function addCustomRoute(app) {
app.get('/', (_req, res) => {
res.send('My custom response') // Replace this with your desired response
})
}
export const mySetupFunction = async ({ app }) => {
addCustomRoute(app)
}

function addCustomRoute(app) {
app.get('/', (_req, res) => {
res.send('My custom response') // Replace this with your desired response
})
}
This will replace the default "Hello world" response with your custom response. Source: Server Config (https://wasp-lang.dev/docs/project/server-config) By using this method, you can customize the root route response without directly modifying the generated code, which would be overwritten on subsequent builds. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Hastur, 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?
martinsos
martinsos2mo ago
Ah yeah we need to remove that! I wonder if what Kapa said here would actually work hm
Want results from more Discord servers?
Add your server