I have a full-stack application that I’m using Express static to serve the client. The issue I’m experiencing is that my server.js
file is running the server on 5000
, however my client views are ran on 5173
. When I run the following, I will see the log on 5000
, but not on 5173
. Should I be seeing it on 5173
? I’m not sure I’m understanding the docs to be able to run Middleware before my client.
Example:
const myMw = (eq, res, next) => {
console.log('MIDDLEWARE RAN');
next();
};
app.use(myMW).use("/test", express.static(path.join(__dirname, 'client')));
app.listen(5000, () => {
console.log(`listening on port: ${port}!`);
});
if I go to localhost:5000/test
I see MIDDLEWARE RAN
in my terminal
if I go to localhost:5173/test
I don’t receive anything in my terminal or my browser console. But it renders my application.
Am I misunderstanding what should be happening here? I want to validate that a user went to a specific URL server-side, ie: /login
before rendering the application.