-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
28 lines (21 loc) · 821 Bytes
/
server.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
import Nullstack from 'nullstack'
import { MongoClient, ServerApiVersion } from 'mongodb'
import Application from './src/Application'
import { MyServerContext } from './src/interfaces/myServerContext'
const context = Nullstack.start(Application) as MyServerContext
context.start = async function start() {
// https://nullstack.app/pt-br/inicializacao-da-aplicacao
const { secrets } = context
if (typeof secrets.mongodbUri === 'string' && typeof secrets.databaseName === 'string') {
const databaseClient = new MongoClient(secrets.mongodbUri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
},
})
await databaseClient.connect()
context.database = await databaseClient.db(secrets.databaseName)
}
}
export default context