Skip to content

Commit f696918

Browse files
committed
use hostname 0.0.0.0 for Next.js server
1 parent 4ae1bb0 commit f696918

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/next.js/index.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
import { parse } from 'url';
2-
import { default as next } from 'next';
3-
import type { Request } from 'firebase-functions/v2/https';
4-
import type { Response } from 'express';
5-
import LRU from 'lru-cache';
6-
import { NextServer } from 'next/dist/server/next.js';
1+
import { parse } from "url";
2+
import { default as next } from "next";
3+
import type { Request } from "firebase-functions/v2/https";
4+
import type { Response } from "express";
5+
import LRU from "lru-cache";
6+
import { NextServer } from "next/dist/server/next.js";
77

88
const nextAppsLRU = new LRU<string, NextServer>({
9-
// TODO tune this
10-
max: 3,
11-
allowStale: true,
12-
updateAgeOnGet: true,
13-
dispose: (server) => {
14-
server.close();
15-
}
9+
// TODO tune this
10+
max: 3,
11+
allowStale: true,
12+
updateAgeOnGet: true,
13+
dispose: (server) => {
14+
server.close();
15+
},
1616
});
1717

1818
export const handle = async (req: Request, res: Response) => {
19-
const { hostname, protocol, url } = req;
20-
const port = protocol === 'https' ? 443 : 80;
21-
const key = [hostname, port].join(':');
22-
// I wish there was a better way to do this, but it seems like this is the
23-
// way to go. Should investigate more if we can get hostname/port to be
24-
// dynamic for middleware.
25-
let nextApp = nextAppsLRU.get(key);
26-
if (!nextApp) {
27-
nextApp = next({
28-
dev: false,
29-
dir: process.cwd(),
30-
hostname,
31-
port
32-
});
33-
nextAppsLRU.set(key, nextApp);
34-
}
35-
await nextApp.prepare();
36-
const parsedUrl = parse(url, true);
37-
nextApp.getRequestHandler()(req, res, parsedUrl);
19+
const { hostname, protocol, url } = req;
20+
const port = protocol === "https" ? 443 : 80;
21+
const key = [hostname, port].join(":");
22+
// I wish there was a better way to do this, but it seems like this is the
23+
// way to go. Should investigate more if we can get hostname/port to be
24+
// dynamic for middleware.
25+
let nextApp = nextAppsLRU.get(key);
26+
if (!nextApp) {
27+
nextApp = next({
28+
dev: false,
29+
dir: process.cwd(),
30+
hostname: "0.0.0.0",
31+
port,
32+
});
33+
nextAppsLRU.set(key, nextApp);
34+
}
35+
await nextApp.prepare();
36+
const parsedUrl = parse(url, true);
37+
nextApp.getRequestHandler()(req, res, parsedUrl);
3838
};

0 commit comments

Comments
 (0)