forked from BaseAdresseNationale/adresse.data.gouv.fr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
110 lines (92 loc) · 2.74 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const express = require('express')
const next = require('next')
const compression = require('compression')
const port = process.env.PORT || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({dev})
const handle = app.getRequestHandler()
app.prepare().then(() => {
const server = express()
if (!dev) {
server.use(compression())
}
server.get('/explore/commune/:code', (req, res) => {
app.render(req, res, '/explore/commune', {
...req.query,
codeCommune: req.params.code
})
})
server.get('/explore/commune/:codeCommune/voie/:idVoie', (req, res) => {
app.render(req, res, '/explore/commune/voie', {
...req.query,
codeCommune: req.params.codeCommune,
idVoie: req.params.idVoie
})
})
server.get('/explore/commune/:codeCommune/voie/:idVoie/numero/:numero', (req, res) => {
app.render(req, res, '/explore/commune/voie', {
...req.query,
codeCommune: req.params.codeCommune,
idVoie: req.params.idVoie,
numero: req.params.numero
})
})
server.get('/bases-locales/validateur', (req, res) => {
app.render(req, res, '/bases-locales/validator', {
...req.query
})
})
server.get('/bases-locales/jeux-de-donnees', (req, res) => {
app.render(req, res, '/bases-locales/datasets', {
...req.query
})
})
server.get('/bases-locales/jeux-de-donnees/:id', (req, res) => {
app.render(req, res, '/bases-locales/datasets/dataset', {
...req.query,
id: req.params.id
})
})
server.get('/bases-locales/jeux-de-donnees/:id/rapport', (req, res) => {
app.render(req, res, '/bases-locales/datasets/dataset/report', {
...req.query,
id: req.params.id
})
})
server.get('/bases-locales/jeux-de-donnees/:id/:codeCommune', (req, res) => {
app.render(req, res, '/bases-locales/datasets/dataset/commune', {
...req.query,
id: req.params.id,
codeCommune: req.params.codeCommune
})
})
server.get('/bases-locales/jeux-de-donnees/:id/:codeCommune/:codeVoie', (req, res) => {
app.render(req, res, '/bases-locales/datasets/dataset/commune/voie', {
...req.query,
id: req.params.id,
codeCommune: req.params.codeCommune,
codeVoie: req.params.codeVoie
})
})
// DO NOT REMOVE
server.get('/api', (req, res) => {
res.redirect('https://geo.api.gouv.fr/adresse')
})
// DO NOT REMOVE
server.get('/download', (req, res) => {
res.redirect('/donnees-nationales')
})
// DO NOT REMOVE
server.get('/contrib', (req, res) => {
res.redirect('/contribuer')
})
server.get('*', (req, res) => {
return handle(req, res)
})
server.listen(port, err => {
if (err) {
throw err
}
console.log(`> Ready on http://localhost:${port}`)
})
})