-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
36 lines (30 loc) · 1.14 KB
/
index.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
import cors from 'cors'
import dotenv from 'dotenv'
import express, { Express, Request, Response } from 'express'
import { connectToDatabase } from './src/connections/mongodb'
import { newsletterRouter } from './src/routes/newsletterUser.routes'
dotenv.config()
export const app: Express = express()
const port: string = process.env.PORT || '420'
const host: string = process.env.HOST || 'http://localhost:'
const dbUri: string = process.env.MONGO_ATLAS_URI || ''
const dbName: string = process.env.DB_NAME || ''
const UriQueryParam: string = process.env.QUERY_PARAMETERS || ''
// Body parsing Middleware
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(cors())
app.use(newsletterRouter)
app.get('/', async (req: Request, res: Response): Promise<Response> => {
return res.status(200).send({ message: 'Achilles' })
})
try{
app.listen(port, (): void => {
/* eslint-disable no-console */
console.log(`Connected successfully to ${host}${port}`)
})
} catch (error: any) {
console.error(`Error occurred: ${error.message}`)
/* eslint-enable no-console */
}
connectToDatabase(dbUri + dbName + UriQueryParam)