-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (25 loc) · 953 Bytes
/
app.js
File metadata and controls
34 lines (25 loc) · 953 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;
const SplitFactory = require('@splitsoftware/splitio').SplitFactory;
const factory = SplitFactory({
core: {
authorizationKey: '<your split api key>'
}
});
const client = factory.client();
app.use(express.json());
app.listen(port, () => {
console.log(`Horror movie app is running on port ${port}.`);
});
const treatmentMiddleware = (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);