index.js
1.07 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
const Koa = require('koa');
const cors = require('@koa/cors');
const Router = require('koa-router');
const bodyparser = require('koa-bodyparser');
const Mongoose = require('mongoose');
const api = require('./src/api');
const updateMedicineInfo = require('./src/lib/UpdatingMedicineInfo');
const MqttServer = require('./src/util/MqttServer');
require('dotenv').config();
// eslint-disable-next-line no-undef
const { SERVER_PORT, MONGO_URL } = process.env;
const app = new Koa();
const router = new Router();
Mongoose.connect(MONGO_URL, {
useFindAndModify : false,
useNewUrlParser : true,
useUnifiedTopology: true,
useCreateIndex : true
}).then(() => {
console.log('\x1b[1;32mMongo DB is connected : ', MONGO_URL, '\x1b[0m');
// updateMedicineInfo.updateMedicineInfo();
}).catch(e => {
console.log(e);
})
app.use(bodyparser());
router.use('/api', api.routes());
app.use(cors());
app.use(router.routes()).use(router.allowedMethods());
app.listen(SERVER_PORT, () => {
console.log('\x1b[1;36mPORT : ', SERVER_PORT, 'is connected\x1b[0m');
MqttServer.on();
})