W
Wasp-lang4mo ago
james

about custom route

Does anyone try add a custom route follow the docs? Does not work for me. My res message not show up. The page is a nav bar with a blank background
10 Replies
matijash
matijash4mo ago
hey James, you are referring to adding a custom API route?
martinsos
martinsos4mo ago
Hey, not sure waht you are referring to -> is it about frontend route (route MyRoute { ..., in main.wasp), or is it API route (api SomeApi {... in main.wasp)? Pls share a bit more about what you tried (code example) and explain what didn't work (what you expected, what happened).
james
james4mo ago
for main.wasp i add server:{ setupFn: import { mySetupFunction } from "@server/myServerSetupCode.js", }, in my myServerSetupCode.ts I add import { ServerSetupFn, Application } from '@wasp/types' export const mySetupFunction: ServerSetupFn = async ({ app }) => { addCustomRoute(app) } function addCustomRoute(app: Application) { app.get('/customRoute', (_req, res) => { res.send('I am a custom route') }) }` this is what I get
No description
No description
james
james4mo ago
I expected this should be a blank page response "I am a custom route" only, instead it show the nav bar and a blank background. and for every page the response is the same what I want to do is to create a custom route for me to handle, like this :
MEE6
MEE64mo ago
Wohooo @james, you just became a Waspeteer level 1!
james
james4mo ago
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
const port = 3000;



// Proxy route to Docker service
app.use('/docker-service', createProxyMiddleware({ target: 'http://docker-service-host:docker-service-port', changeOrigin: true }));

app.listen(port, () => {
console.log(`Node.js app listening at http://localhost:${port}`);
});
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
const port = 3000;



// Proxy route to Docker service
app.use('/docker-service', createProxyMiddleware({ target: 'http://docker-service-host:docker-service-port', changeOrigin: true }));

app.listen(port, () => {
console.log(`Node.js app listening at http://localhost:${port}`);
});
@martinsos My fault, checking the wrong page
martinsos
martinsos4mo ago
@james ah sorry for being so late with the response -> great you figured it out! What is not great on our side is that we just have a blank page, we have to improve that. Any idea what else we could have done to possibly prevent the issue you had? Has Wasp or us somehow made it easy to shoot yourself in the foot here?
james
james4mo ago
I just look the wrong port. Setup on server, but looking client. It is all fine now. Thank you so much