-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patheosdac-api.js
executable file
·57 lines (45 loc) · 1.47 KB
/
eosdac-api.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
#!/usr/bin/env node
process.title = 'eosdac-api';
const openApi = require('./open-api');
const {loadConfig} = require('./functions');
const path = require('path');
const config = loadConfig();
const logger = require('./connections/logger')('eosdac-api', config.logger);
const fastify = require('fastify')({
ignoreTrailingSlash: true,
trustProxy: true,
logger
});
fastify.register(require('fastify-oas'), openApi.options);
fastify.register(require('fastify-autoload'), {
dir: path.join(__dirname, 'api-handlers'),
options: {
prefix: '/v1/eosdac'
}
});
const mongo_url = `${config.mongo.url}/${config.mongo.dbName}`;
fastify.register(require('fastify-mongodb'), {
url: mongo_url
});
fastify.register(require('./fastify-eos'), config);
fastify.register(require('./fastify-dac'), {});
fastify.register(require('./fastify-config'), config);
// fastify.register(require('./fastify-cache'), {});
fastify.register(require('fastify-cors'), {
allowedHeaders: 'Content-Type,X-DAC-Name',
origin: '*'
});
fastify.ready().then(async () => {
console.log(`Started API server with config ${process.env.CONFIG} on ${process.env.SERVER_ADDR || '127.0.0.1'}:${process.env.SERVER_PORT}`);
await fastify.oas();
}, (err) => {
console.error('Error starting API', err)
});
(async () => {
try {
await fastify.listen(process.env.SERVER_PORT, process.env.SERVER_ADDR)
} catch (err) {
fastify.log.error(err);
process.exit(1)
}
})();