File size: 853 Bytes
3f0ac03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const path = require("path");
const express = require("express");
const next = require("next");

const port = parseInt(process.env.PORT || "3000", 10);
const hostname = process.env.HOSTNAME || "0.0.0.0";

const app = next({ dev: false, hostname, port });
const handle = app.getRequestHandler();

app
  .prepare()
  .then(() => {
    const server = express();

    // Serve Next.js build assets and public files explicitly.
    server.use("/_next/static", express.static(path.join(__dirname, ".next", "static")));
    server.use(express.static(path.join(__dirname, "public")));

    server.all("*", (req, res) => handle(req, res));

    server.listen(port, hostname, () => {
      console.log(`Server listening on http://${hostname}:${port}`);
    });
  })
  .catch((err) => {
    console.error("Failed to start server", err);
    process.exit(1);
  });