-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.ts
executable file
·57 lines (43 loc) · 1.74 KB
/
app.ts
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
import 'reflect-metadata'; // this shim is required
import { createKoaServer, useContainer as routingUseContainer, Controller } from 'routing-controllers';
import { useContainer as ormUseContainer, createConnection } from 'typeorm';
import { Container } from 'typedi';
import {User} from './app/models/user'
import currentUserChecker from './app/helpers/currentUserChecker'
import authorizationChecker from './app/helpers/authorizationChecker'
// config ioc container
routingUseContainer(Container);
ormUseContainer(Container);
// // init all db models
// createConnection().then(() => {
// const app = createKoaServer({
// controllers: [__dirname + '/app/apis/*.js'],
// middlewares: [__dirname + '/lib/middlewares/*.js'],
// defaultErrorHandler: false,
// authorizationChecker: authorizationChecker,
// currentUserChecker: currentUserChecker,
// });
// // start listen
// const nodeEnv = process.env.NODE_ENV || 'development';
// const port = process.env.PORT || 4001;
// app.listen(port, () => console.log('server started, port ' + port + ' env ' + nodeEnv));
// }).catch(error => console.log('Error: ', error));
async function createConnServer() {
await createConnection()
const app = createKoaServer({
controllers: [__dirname + '/app/apis/*.js'],
middlewares: [__dirname + '/lib/middlewares/*.js'],
defaultErrorHandler: true,
authorizationChecker: authorizationChecker,
currentUserChecker: currentUserChecker,
});
// start listen
const nodeEnv = process.env.NODE_ENV || 'development';
const port = process.env.PORT || 4001;
app.listen(port, () => console.log('server started, port ' + port + ' env ' + nodeEnv));
}
try {
createConnServer()
} catch(error) {
console.log('Error: ', error)
}