-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
66 lines (56 loc) · 1.94 KB
/
app.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
let express = require('express');
let cookieParser = require('cookie-parser');
let bodyParser = require('body-parser');
let routeV2 = require('./routes/v2/route');
let jobs = require('./jobs/jobs');
let jobsV2 = require('./jobs/jobsV2');
let jobsEth = require('./jobs/jobsEth');
let jobsFusion = require('./jobs/jobsFusion');
let log4js = require('log4js');
let cors = require('cors');
let { DefaultDIDAdapter } = require('@elastosfoundation/did-js-sdk');
let {DIDBackend} = require('@elastosfoundation/did-js-sdk');
log4js.configure({
appenders: {
file: { type: 'dateFile', filename: 'logs/pasar.log', pattern: ".yyyy-MM-dd.log", compress: true, },
console: { type: 'stdout'}
},
categories: { default: { appenders: ['file', 'console'], level: 'info' } },
pm2: true,
pm2InstanceVar: 'INSTANCE_ID'
});
global.logger = log4js.getLogger('default');
global.fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const corsOpts = {
origin: '*',
methods: [
'GET',
'POST',
],
allowedHeaders: [
'Content-Type',
],
};
let app = express();
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(log4js.connectLogger(logger, { level: log4js.levels.INFO }));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(cors(corsOpts));
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.use('/api/v2', routeV2);
let resolverUrl = "https://api.trinity-tech.cn/eid";
DIDBackend.initialize(new DefaultDIDAdapter(resolverUrl));
jobs.run()
jobsV2.run()
jobsEth.run();
jobsFusion.run();
module.exports = app;