forked from etalab/apicarto
-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
115 lines (87 loc) · 3.27 KB
/
app.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
111
112
113
114
115
import path from 'path';
import { fileURLToPath } from 'url';
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import { requestLogger } from './middlewares/request-logger.js';
import { router as cadastre } from './controllers/cadastre/index.js';
import { router as aoc } from './controllers/aoc/index.js';
import { router as codes_postaux } from './controllers/codes-postaux/index.js';
import { router as gpu } from './controllers/gpu/index.js';
import { router as rpg } from './controllers/rpg/index.js';
import { router as nature } from './controllers/nature/index.js';
import { router as wfs_geoportail } from './controllers/wfs-geoportail/index.js';
import { router as er } from './controllers/er/index.js';
import { router as corse } from './controllers/corse/index.js';
import { router as health } from './controllers/health/index.js';
import { datasets } from './datasets/index.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
var app = express();
/* Mentions légales */
app.get('/api/doc/mentions', function(req,res){
res.render('mentions');
});
/*------------------------------------------------------------------------------
* common middlewares
------------------------------------------------------------------------------*/
var env = process.env.NODE_ENV;
if (env === 'production') {
// see http://expressjs.com/fr/guide/behind-proxies.html
app.enable('trust proxy');
}
app.use(bodyParser.json());
app.use(cors());
app.use(function (req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next();
});
app.use(requestLogger());
/*------------------------------------------------------------------------------
* /api/doc - expose documentation
-----------------------------------------------------------------------------*/
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, '/doc/views'));
app.use(
'/api/doc/vendor/swagger-ui',
express.static(__dirname + '/node_modules/swagger-ui-dist')
);
app.use('/api/doc', express.static(__dirname + '/doc'));
app.get('/api/doc',function(req,res){
res.render('index',{datasets: datasets});
});
app.get('/api/doc/:moduleName', function(req,res){
res.render('module',{moduleName: req.params.moduleName});
});
app.get('/', function (req, res) {
res.redirect('/api/doc/');
});
app.get('/api/', function (req, res) {
res.redirect('/api/doc/');
});
/* -----------------------------------------------------------------------------
* Routes
-----------------------------------------------------------------------------*/
/* Module cadastre */
app.use('/api/cadastre', cadastre);
/* Module AOC */
app.use('/api/aoc',aoc);
/* Module code postaux */
app.use('/api/codes-postaux', codes_postaux);
/* Module GPU */
app.use('/api/gpu',gpu);
/* Module RPG */
app.use('/api/rpg',rpg);
/* Module Nature */
app.use('/api/nature',nature);
/* Module all module IGN */
app.use('/api/wfs-geoportail',wfs_geoportail);
/* Module Espace Revendeur */
app.use('/api/er',er);
/* Module Dreal Corse */
app.use('/api/corse/',corse);
/* Endpoints dédié à la surveillance */
app.use('/api/health/',health);
export {app};