Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import path from "path";
- import fastifyStatic from "fastify-static";
- import fastifyInstance from "fastify";
- import fastifyNextJS from "fastify-nextjs";
- import routes from "./routes";
- const port = parseInt(process.env.PORT || "4200", 10);
- const dev = process.env.NODE_ENV !== "production";
- const fastify = fastifyInstance({
- logger: { level: "error" },
- trustProxy: true,
- });
- const initNext = async () => {
- // todo: https://github.com/typedef42/nextjs-fastify-i18n/blob/master/next.config.js
- // config: require('next.config.json')()
- fastify
- .register(fastifyNextJS, {
- dev,
- })
- .after(() => {
- console.log(fastify.next);
- fastify.next("/");
- });
- fastify.register((instance, _opts, next) => {
- instance.register(fastifyStatic, {
- root: path.join(__dirname, "public"),
- prefix: "/",
- });
- next();
- });
- };
- (async function () {
- routes(fastify);
- await initNext();
- fastify.listen(port, (err, address) => {
- if (err) {
- console.error(err);
- process.exit(1);
- }
- console.log(`Server listening ${address}`);
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment