-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
28 lines (25 loc) · 880 Bytes
/
server.js
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
// server.js
const mongoose = require("mongoose");
const { createServer } = require("http");
const { parse } = require("url");
const next = require("next");
const isDev = process.env.NODE_ENV !== "production";
const hostname = "localhost";
const port = 3000;
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev: isDev, hostname, port });
const handle = app.getRequestHandler();
const mongooseConnectionOptions = {
bufferCommands: false,
};
app.prepare().then(() => {
createServer(async (req, res) => {
const parsedUrl = parse(req.url, true);
await handle(req, res, parsedUrl);
}).listen(port, async (err) => {
if (err) throw err;
mongoose.set("strictQuery", true);
await mongoose.connect(process.env.MONGODB_URI, mongooseConnectionOptions);
console.info(`> Ready on http://${hostname}:${port}`);
});
});