app.js
1.19 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
const express = require('express');
const bodyParser = require('body-parser');
const requestIp = require('request-ip');
const app = express();
const config = require('./common/config');
const logger = require('yoho-node-lib/lib/logger').init(config);
const crypto = require('yoho-node-lib/lib/crypto');
global.yoho = {
logger,
config,
crypto
};
app.use(bodyParser.text({
limit: '1024kb'
}));
app.use(function(req, res, next) {
req.clientIp = requestIp.getClientIp(req);
next();
});
try {
const middleware = require('./middleware');
app.get('/', (req, res) => {
res.send('首页');
});
app.get('/apm/yas.gif', middleware.apm);
// docker验证项目是否正常发布
app.use('/node/status.html', (req, res) => {
return res.status(204).end();
});
// 新方法
app.get('/apm/yas2.gif', middleware.clientApm);
app.post('/write', middleware.serverApm);
} catch (e) {
logger.error(e);
}
app.use('*', (req, res) => {
res.statusCode = 404;
res.send();
});
app.use((err, req, res) => {
logger.error('error:', err);
res.send();
});
app.listen(config.port, () => {
logger.info(`yoho apm start at ${config.port}`);
});