-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·34 lines (25 loc) · 1000 Bytes
/
app.js
File metadata and controls
executable file
·34 lines (25 loc) · 1000 Bytes
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
const express = require('express');
const app = express();
const port = 5000;
app.use(express.json());
app.listen(port, () => {
console.log(`Horror movie app is running on port ${port}.`);
});
const SplitFactory = require('@splitsoftware/splitio').SplitFactory;
const factory = SplitFactory({
core: {
authorizationKey: '7m4qctr1k6vi9kshbbu972vqm8nklom6qnjh'
}
});
const client = factory.client();
const treatmentMiddleware = function (request, response, next) {
const userEmail = request.headers['authorization'];
request.treatment = client.getTreatment(userEmail, 'database_split');
next();
}
const api = require('./api');
app.get('/horrors/', treatmentMiddleware, api.getAllHorrors);
app.get('/horrors/:id', treatmentMiddleware, api.getHorrorById);
app.post('/horrors/', treatmentMiddleware, api.addHorror);
app.put('/horrors/:id', treatmentMiddleware, api.updateHorror);
app.delete('/horrors/:id', treatmentMiddleware, api.deleteHorror);