fasttify停止生产模式



你好,我想运行fasttify与react构建文件的前端。我不知道为什么当我运行我的服务器时,它在运行后停止。

yarn run v1.22.10 $ node dist/src/index.js服务器已在端口就绪4000 . 3.03秒完成。

我代码:

app.register((instance, opts, next) => {
instance.register(fastifyStatic, {
root: path.join(__dirname, "build"),
prefix: "/*/",
});
next();
});
server.start().then(() => {
app.register(server.createHandler({ path: "/graphql", cors: corsOptions }));
app.listen(PORT, "0.0.0.0", (err) => {
if (err) {
console.error(err);
} else {
console.log("Server is ready at port 5000");
}
});
});

我找到了解决方案。但我仍然可以去操场。如果我弄明白了,我会更新的。

app.register((instance, opts, next) => {
instance.register(fastifyStatic, {
root: path.join(__dirname, "build"),
prefix: "/",
});
instance.setNotFoundHandler((req, res) => {
res.sendFile("index.html", path.join(__dirname, "build"));
});
next();
});

最新更新