forked from ricardocasares/bemba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (28 loc) · 1 KB
/
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
29
30
const next = require("next");
const express = require("express");
const { join } = require("path");
const { parse } = require("url");
const static = require("serve-static");
const { NODE_ENV, PORT = 3000 } = process.env;
const dir = join(__dirname, "static");
const dev = NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const render = name => (req, res) =>
app.render(req, res, name, { ...req.query, ...req.params });
app.prepare().then(() =>
express()
.use(static(dir))
.get("/", render("/"))
.get("/search", render("/search"))
.get("/library", render("/library"))
.get("/settings", render("/settings"))
.get("/:filter/:name", render("/stations"))
.get("/radio/:id/:slug", render("/station"))
.get("/stations/:filter/:name", (req, res) => {
const { filter, name } = req.params;
res.redirect(301, `/${filter}/${name}`);
})
.get("*", (req, res) => handle(req, res))
.listen(PORT, () => console.log(`> Server ready`))
);