-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
75 lines (57 loc) · 2.65 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const express = require('express');
const next = require('next');
const compression = require('compression');
const helmet = require('helmet');
const serveStatic = require('serve-static');
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare()
.then(() => {
const server = express();
server.use(helmet());
server.use(compression());
server.use(serveStatic('static', {'index': ['default.html', 'default.htm']}));
server.get('/products', (req, res) => {
app.render(req, res, '/products', req.query);
});
server.get('/products/:slug', (req, res) => {
app.render(req, res, '/product', Object.assign({}, req.params, req.query));
});
server.get('/collections/:slug', (req, res) => {
app.render(req, res, '/collection', Object.assign({}, req.params, req.query));
});
//TODO: dynamic route from GraphQL
server.get('/philosophy', (req, res) => {
app.render(req, res, '/content', Object.assign({}, req.params, req.query, {slug: 'philosophy'}));
});
server.get('/frames', (req, res) => {
app.render(req, res, '/content', Object.assign({}, req.params, req.query, {slug: 'frames'}));
});
server.get('/lenses', (req, res) => {
app.render(req, res, '/content', Object.assign({}, req.params, req.query, {slug: 'lenses'}));
});
server.get('/craftsmanship', (req, res) => {
app.render(req, res, '/content', Object.assign({}, req.params, req.query, {slug: 'craftsmanship'}));
});
server.get('/grandvision', (req, res) => {
app.render(req, res, '/legal', Object.assign({}, req.params, req.query, {slug: 'grandvision'}));
});
server.get('/cookie-policy', (req, res) => {
app.render(req, res, '/legal', Object.assign({}, req.params, req.query, {slug: 'cookie-policy'}));
});
server.get('/privacy-policy', (req, res) => {
app.render(req, res, '/legal', Object.assign({}, req.params, req.query, {slug: 'privacy-policy'}));
});
server.get('/terms-and-conditions', (req, res) => {
app.render(req, res, '/legal', Object.assign({}, req.params, req.query, {slug: 'terms-and-conditions'}));
});
server.get('*', (req, res) => {
return handle(req, res)
});
server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`)
})
});