-
Hey again! Not sure if it's better to have a discussion rather an issue but I'm trying to get a server running with fastify. const fastify = require("fastify");
const fastifyStatic = require("fastify-static");
const path = require("path");
const { ssr } = require("./dist/server/package.json");
const manifest = require("./dist/client/ssr-manifest.json");
const { default: renderPage } = require("./dist/server");
const server = fastify({
logger: false,
});
server.register(fastifyStatic, {
root: __dirname,
});
for (const asset of ssr.assets || []) {
server.get("/" + asset, (request, reply) => {
reply.send("client/" + asset);
});
}
server.get("*", async (request, reply) => {
const url = request.protocol + "://" + request.headers.host + request.url;
const { html } = await renderPage(url, {
manifest,
preload: true,
request,
response: reply,
});
reply.type("text/html").send(html);
});
startServer();
async function startServer() {
try {
await server.listen(3030);
} catch (e) {
console.error(e);
process.exit(1);
}
} In the express example I need to serve the assets statically, that's why I thought I need to use Specifying the root as Any idea what I need to change here to have the same behavior as the express server? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
@MarvinRudolph Hi! I think you just need to serve Please tell me if that works 👍 |
Beta Was this translation helpful? Give feedback.
@MarvinRudolph Hi! I think you just need to serve
dist/client
for static files. The way we do it in Express (1 by 1) is just to prevent servingssr-manifest.json
but I guess that's not a very big issue. Originally, it was also preventing serving the dummyclient/index.html
but this file is now removed so it shouldn't affect you.Please tell me if that works 👍