forked from timJFrame/sei-project-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (30 loc) · 1 KB
/
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
41
42
import express from 'express'
import { port } from './config/environment.js'
import logger from './lib/logger.js'
import connectToDatabase from './lib/connectToDB.js'
import router from './config/router.js'
import errorHandler from './lib/errorHandler.js'
import path from 'path'
const app = express()
const __dirname = path.resolve()
async function startServer() {
try {
await connectToDatabase()
console.log('Database has connected')
app.use(express.static(`${__dirname}/client/build`))
//*Makes req.body available
app.use(express.json())
//*Logger logs each request to the console
app.use(logger)
//*Routes all routes
app.use('/api', router)
app.use('/*', (_, res) => res.sendFile(`${__dirname}/client/build/index.html`))
//*Handles errors
app.use(errorHandler)
app.listen(port, () => console.log(`🤖 Up and running on port ${port}`))
} catch (err) {
console.log('🤖 Something went wrong starting the App')
console.log(err)
}
}
startServer()