-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 948 Bytes
/
index.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
import config from './config.js'
import { app } from './app'
import { AppRoutes } from './routes'
import auth from './middleware/auth'
import { PrismaClient } from '@prisma/client'
export const prisma = new PrismaClient()
async function main() {
await prisma.$connect()
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
console.log(`PRISMA ${prisma._clientVersion}`)
AppRoutes.forEach(route => {
const controller = (request, response, next) => {
route.action(request, response)
.then(() => next)
.catch(err => next(err))
}
let args = [route.path, auth, controller]
if(!route.auth) {
args.splice(1, 1)
}
app[route.method](...args)
})
app.listen(config.PORT, config.HOST, () => {
console.log(`APP LISTENING ON: http://${config.HOST}:${config.PORT}`);
})