-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
109 lines (87 loc) · 2.4 KB
/
index.ts
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
import express, { Express, Request, Response } from 'express';
import dotenv from 'dotenv';
import { rneControllerAPI, rneControllerSite } from './src/controllers/rne';
import { errorHandler } from './src/controllers/errorHandler';
import { associationController } from './src/controllers/association';
import * as Sentry from '@sentry/node';
import helmet from 'helmet';
import statusRouter from './src/routes/status';
import { rneListDocumentsController } from './src/controllers/rne-document';
import {
rneActeDownloadController,
rneBilanDownloadController,
} from './src/controllers/rne-download';
import { tvaController } from './src/controllers/tva';
import { eoriController } from './src/controllers/eori';
import { igController } from './src/controllers/ig';
dotenv.config();
const app: Express = express();
const port = process.env.PORT || 3000;
const useSentry =
process.env.NODE_ENV === 'production' && process.env.SENTRY_DSN;
// parse incoming request json body
app.use(express.json());
// https://expressjs.com/fr/advanced/best-practice-security.html
app.use(helmet());
/**
* Error handling
*/
if (useSentry) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [],
});
// The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
}
/**
* Up and running
*/
app.get('/', (req: Request, res: Response) => {
res.json({ message: 'Server is up and running' });
});
/**
* RNE
*/
app.get('/rne/:siren', rneControllerAPI);
/**
* RNE Fallback
*/
app.get('/rne/fallback/:siren', rneControllerSite);
// list documents
app.get('/rne/documents/:siren', rneListDocumentsController);
// download an acte
app.get('/rne/download/acte/:id', rneActeDownloadController);
// download a bilan
app.get('/rne/download/bilan/:id', rneBilanDownloadController);
/**
* Status
*/
app.use('/status', statusRouter);
/**
* Association
*/
app.use('/association/:rna', associationController);
/**
* TVA
*/
app.use('/tva/:tvaNumber', tvaController);
/**
* EORI
*/
app.use('/eori/:siret', eoriController);
/**
* IG
*/
app.use('/ig/:siren', igController);
/**
* Error handling
*/
if (useSentry) {
// The error handler must be before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler());
}
app.use(errorHandler);
app.listen(port, () => {
console.log(`⚡️[server]: Server is running at https://localhost:${port}`);
});