-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (52 loc) · 1.71 KB
/
index.js
File metadata and controls
62 lines (52 loc) · 1.71 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const koa = require('koa');
const ctRegisterMicroservice = require('ct-register-microservice-node');
const logger = require('./logger');
var bodyParser = require('koa-bodyparser');
const app = koa();
app.use(bodyParser({
jsonLimit: '50mb'
}));
app.use(function *(next){
if(this.path === '/awesome'){
try{
logger.debug('Body', this.request.body);
logger.debug('Query', this.request.query);
// let result = yield ctRegisterMicroservice.requestToMicroservice({
// uri: '/users/4',
// method: 'GET',
// json: true,
// });
// // logger.debug('result', result);
// this.body = result;
this.body = 1;
return;
} catch (err){
logger.error(err);
this.throw(500, 'Unexpected error');
}
}
yield next;
})
//Instance of http module
var server = require('http').Server(app.callback());
// get port of environment, if not exist obtain of the config.
// In production environment, the port must be declared in environment variable
var port = process.env.PORT || 3000;
server.listen(port, () => {
ctRegisterMicroservice.register({
info: require('./microservice/register.json'),
swagger: require('./microservice/swagger.json'),
mode: ctRegisterMicroservice.MODE_AUTOREGISTER,
framework: ctRegisterMicroservice.KOA1,
app,
logger,
name: 'microservice-koa1',
ctUrl: process.env.CT_URL,
url: process.env.LOCAL_URL,
active: true,
}).then(() => {}, (err) => {
logger.error(err);
process.exit(1);
});
});
logger.info('Server started in port:' + port);