-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (41 loc) · 1.16 KB
/
app.js
File metadata and controls
48 lines (41 loc) · 1.16 KB
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
// Requires for this skill
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
var fs = require('fs');
var async = require('async');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
/*
* function to initialize all modules that are located in the app_modules directory
*/
function init(cb) {
var modulePath = path.resolve(path.join(__dirname, './app_modules'));
fs.readdir(modulePath, function(err, services) {
var moduleArray = [];
services.forEach(function(module) {
moduleArray.push(require('./app_modules/' + module));
});
async.series(moduleArray, function(err, results) {
if (err) {
console.error(err);
} else {
cb();
}
});
});
}
init(function() {
// Manually hook the handler function into express
app.post('/:service', function(req, res) {
//console.log(req.body);
// console.log(req.params);
global[req.params.service].request(req.body)
.then(function(response) {
console.log(response);
res.json(response);
});
});
app.listen(process.env.PORT);
});