-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.js
45 lines (35 loc) · 969 Bytes
/
app.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
43
44
45
const config = require('dotenv').config()
const cors = require('cors')
const express = require('express')
const healthRouter = require("./routes/health")
const notesRouter = require("./routes/notes")
const noteRouter = require("./routes/note")
if (config.error) {
throw config.error
}
const port = process.env.PORT // || 3001
global.port = port
const corsOptions ={
origin:'*',
credentials:true,
optionSuccessStatus:200,
}
const app = express()
app.use(cors(corsOptions))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
/*
TODO-1: Settup Database connection
*/
/*
TODO-2: Upon database connection success, create the relavent table(s) if it does not exist.
*/
app.get('/', (req, res) => {
res.send('CSBC1010 Assignment 3 - My Notes')
})
app.use("/health", healthRouter)
app.use("/notes", notesRouter)
app.use("/note", noteRouter)
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`)
})