1 | 'use strict';
|
2 |
|
3 | var a127 = require('a127-magic');
|
4 | var express = require('express');
|
5 | var app = express();
|
6 |
|
7 | module.exports = app;
|
8 |
|
9 |
|
10 | a127.init(function(config) {
|
11 |
|
12 |
|
13 | app.use(a127.middleware(config));
|
14 |
|
15 |
|
16 | app.use(function(err, req, res, next) {
|
17 | if (typeof err !== 'object') {
|
18 |
|
19 | err = {
|
20 | message: String(err)
|
21 | };
|
22 | } else {
|
23 |
|
24 | Object.defineProperty(err, 'message', { enumerable: true });
|
25 | }
|
26 |
|
27 |
|
28 | res.set('Content-Type', 'application/json');
|
29 | res.end(JSON.stringify(err));
|
30 | });
|
31 |
|
32 | var ip = process.env.IP || 'localhost';
|
33 | var port = process.env.PORT || 10010;
|
34 |
|
35 | app.listen(port, ip);
|
36 |
|
37 | console.log('try this:\ncurl http://' + ip + ':' + port + '/hello?name=Scott');
|
38 | });
|