forked from navikt/foreldrepengesoknad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock-api-server.js
97 lines (76 loc) · 2.66 KB
/
mock-api-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
const express = require('express');
const app = express();
const router = express.Router();
const multer = require('multer');
const MockStorage = require('./mock-storage');
require('dotenv').config();
const allowCrossDomain = function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080');
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type,X-XSRF-TOKEN,Location');
res.setHeader('Access-Control-Expose-Headers', 'Location');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
};
const delayAllResponses = function(millis) {
return function(req, res, next) {
setTimeout(next, millis);
};
};
app.use(allowCrossDomain);
app.use(delayAllResponses(500));
app.use(express.json());
router.get(['/rest/sokerinfo'], (req, res) => {
res.send(MockStorage.getSokerInfo());
});
router.post('/rest/engangsstonad', (req, res) => res.sendStatus(200));
router.get('/rest/storage', (req, res) => {
res.send(MockStorage.getSoknad());
});
router.get('/rest/innsyn/saker', (req, res) => {
res.send(MockStorage.getSaker());
});
router.get('/rest/innsyn/uttaksplan', (req, res) => {
res.send(MockStorage.getUttaksplan());
});
router.get('/rest/innsyn/uttaksplanannen', (req, res) => {
res.send(MockStorage.getUttaksplanannen());
});
router.get('/rest/konto', (req, res) => {
res.send(MockStorage.getStønadskontoer());
});
router.post('/rest/storage', (req, res) => {
MockStorage.updateSoknad(req.body);
return res.sendStatus(200);
});
router.delete('/rest/storage', (req, res) => {
return res.sendStatus(200);
});
router.get('/rest/storage/kvittering/foreldrepenger', (req, res) => {
res.send(MockStorage.getStorageKvittering());
});
router.post('/rest/soknad', (req, res) => {
return res.send(MockStorage.getSoknadSendt());
});
router.post('/rest/soknad/endre', (req, res) => {
return res.send(MockStorage.getSoknadSendt());
});
router.delete('/rest/storage', (req, res) => {
res.sendStatus(204);
});
const vedleggUpload = multer({
dest: './dist/vedlegg/'
});
router.post('/rest/storage/vedlegg', vedleggUpload.single('vedlegg'), (req, res) => {
res.setHeader('Location', `http://localhost:8080/foreldrepengesoknad/dist/vedlegg/${req.body.id}`);
res.sendStatus(201);
});
router.delete('/rest/storage/vedlegg/:id', (req, res) => {
res.sendStatus(204);
});
app.use('', router);
const port = process.env.PORT || 8888;
app.listen(port, () => {
console.log(`Mock-api listening on port: ${port}`);
});
const logError = (errorMessage, details) => console.log(errorMessage, details);