I have a legacy backend on Express.js and a frontend on Vue.js. I want to update the frontend to nuxt 3 and make it friends with Express.js, but the option of running the frontend and backend on 2 different ports does not suit me. Are there any options to implement Express in Nuxt on top of or instead of the standard server in Nuxt? Or maybe there are other options…
I tried the following but I get an error
nuxt.config:
serverHandlers: [
{ path: "/server-api*", handler: "~/server-api/app.js" },
],
/server-api/app.js:
import express from "express";
const app = express();
app.use(express.json());
app.get("/server-api/test", (req, res, next) => {
res.send({
message: "HELLO",
});
});
export default fromNodeMiddleware(app)
app.vue for example:
<script>
export default {
async setup() {
const { data: message } = await useFetch("/server-api/test");
return { message };
},
};
</script>
Error:
[nuxt] [request error] [unhandled] [500] Cannot set properties of undefined (setting ‘content-type’)