Guest User

Untitled

a guest
Mar 29th, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import path from "path";
  2. import fastifyStatic from "fastify-static";
  3. import fastifyInstance from "fastify";
  4. import fastifyNextJS from "fastify-nextjs";
  5. import routes from "./routes";
  6.  
  7. const port = parseInt(process.env.PORT || "4200", 10);
  8. const dev = process.env.NODE_ENV !== "production";
  9.  
  10. const fastify = fastifyInstance({
  11.   logger: { level: "error" },
  12.   trustProxy: true,
  13. });
  14.  
  15. const initNext = async () => {
  16.   // todo: https://github.com/typedef42/nextjs-fastify-i18n/blob/master/next.config.js
  17.   // config: require('next.config.json')()
  18.   fastify
  19.     .register(fastifyNextJS, {
  20.       dev,
  21.     })
  22.     .after(() => {
  23.       console.log(fastify.next);
  24.       fastify.next("/");
  25.     });
  26.  
  27.   fastify.register((instance, _opts, next) => {
  28.     instance.register(fastifyStatic, {
  29.       root: path.join(__dirname, "public"),
  30.       prefix: "/",
  31.     });
  32.     next();
  33.   });
  34. };
  35.  
  36. (async function () {
  37.   routes(fastify);
  38.  
  39.   await initNext();
  40.  
  41.   fastify.listen(port, (err, address) => {
  42.     if (err) {
  43.       console.error(err);
  44.       process.exit(1);
  45.     }
  46.  
  47.     console.log(`Server listening ${address}`);
  48.   });
  49. })();
  50.  
Advertisement
Add Comment
Please, Sign In to add comment