-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
49 lines (36 loc) · 1.13 KB
/
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
'use strict';
const express = require('express');
const fs = require('fs');
const path = require('path');
const cors = require('cors');
const PORT = process.env.PORT || 9000;
const app = express();
app.use(cors({
credentials: true,
methods: ['GET', 'POST', 'OPTIONS'],
}));
app.set('view engine', 'pug');
app.get('/', function (req, res) {
fs.readdir(__dirname + '/fixtures', function(err, items) {
var files = items.map(function(item) {
return path.basename(item, '.js');
});
res.render('index', { fixtures: files });
});
});
app.get('/cds-services/:name', function(req, res) {
var fixture = require('./fixtures/' + req.params.name);
res.json(fixture.payload);
});
app.post('/cds-services/:name', function(req, res) {
var fixture = require('./fixtures/' + req.params.name);
res.json(fixture.payload);
});
app.get('/cds-services', function(req, res) {
var services = ['hw-drug-interactions', 'hw-patient-education'].map(function(item) {
return require('./fixtures/' + item).definition;
});
res.json({services: services});
});
app.listen(PORT);
console.log('Running on http://localhost:' + PORT);