-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (40 loc) · 1.28 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
const express = require('express')
const path = require('path')
const next = require('next')
const parseAcceptLanguage = require('parse-accept-language');
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const routes = require('./routes')
const handle = routes.getRequestHandler(app, ({req, res, route, query}) => {
app.render(req, res, route.page, query )
})
app.prepare().then(() => {
const server = express()
server.get('/', function(req, res) {
const locale = parseAcceptLanguage(req)[0].value
switch(locale) {
case 'fr': res.redirect('/fr-fr'); break;
case 'en-GB': res.redirect('/en-gb'); break;
case 'en-US': res.redirect('/en-us'); break;
default: res.redirect('/en-gb');
}
handle(req, res)
})
server.get('/faq', function(req, res) {
const locale = parseAcceptLanguage(req)[0].value
switch(locale) {
case 'fr': res.redirect('/fr-fr/faq'); break;
case 'en-GB': res.redirect('/en-gb/faq'); break;
case 'en-US': res.redirect('/en-us/faq'); break;
default: res.redirect('/en-gb/faq');
}
handle(req, res)
})
server.get('*', function(req, res) {
handle(req, res)
})
server.listen(3000, (err) => {
if (err) throw err
console.log('> Ready on port 3000')
})
});