-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.ts
36 lines (28 loc) · 824 Bytes
/
server.ts
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
31
32
33
34
35
36
import express from "express";
import next from "next";
import admin from "firebase-admin";
import { config } from "./src/config/config";
const port = Number(process.env.PORT) || 3000;
const dev = process.env.NODE_ENV === "development";
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
admin.initializeApp({
credential: admin.credential.cert(config.server.credential as any),
databaseURL: config.server.databaseURL,
});
const server = express();
server.use((req, res, next) => {
req.firebase = admin;
next();
});
server.get("*", (req, res) => {
return handle(req, res);
});
server.listen(port, (err) => {
if (err) throw err;
console.log(
`> Ready Hey on http://localhost:${port} ${process.env.NODE_ENV}`
);
});
});