This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
79 lines (67 loc) · 2.21 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import dotenv from 'dotenv'
import mongoose from 'mongoose'
import express from 'express'
import sporranSession from './routes/sporran/sporranSession.js'
import sporranRequestAttestation from './routes/sporran/sporranRequestAttestation.js'
import sporranTerms from './routes/sporran/sporranTerms.js'
import cors from 'cors'
import Logging from './libraries/Logging.js'
import userRouter from './routes/user.route.js'
import credentialsRouter from './routes/credential.route.js'
import propertyRouter from './routes/property.route.js'
import collectionRouter from './routes/collection.route.js'
import loanRouter from './routes/loan.route.js'
import companyRouter from './routes/company.route.js'
dotenv.config()
mongoose
//.connect("mongodb://localhost/XCAVProperty")
.connect(
process.env.MONGO_DB_URL
)
.then(() => {
console.log("Successfuly connected to DB...")
})
.catch((err) => console.log("Could not connect to db", err.message))
const app = express()
app.use((req, res, next) => {
/** Log the Request */
Logging.info(`Incomming -> Method: [${req.method}] - Url: [${req.url}] - IP: [${req.socket.remoteAddress}]`)
res.on('finish', () => {
/** Log the Response */
Logging.info(`Incomming -> Method: [${req.method}] - Url: [${req.url}] - IP: [${req.socket.remoteAddress}] - Status: [${res.statusCode}]`)
})
next()
})
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
/** Rules of our API */
app.use(
cors({
origin: true,
optionsSuccessStatus: 200,
credentials: true,
}),
)
app.options(
'*',
cors({
origin: true,
optionsSuccessStatus: 200,
credentials: true,
}),
)
app.use("/api/session", sporranSession)
app.use("/api/request-attestation", sporranRequestAttestation)
app.use("/api/terms", sporranTerms)
app.use("/api/user", userRouter)
app.use("/api/credentials", credentialsRouter)
app.use("/api/property", propertyRouter)
app.use("/api/collection", collectionRouter)
app.use("/api/loan", loanRouter)
app.use("/api/company", companyRouter)
/** Healthcheck */
app.get('/foot', (req, res, next) => res.status(200).json({ message: 'ball' }))
const port = process.env.PORT || 3005
app.listen(port, () => {
console.log(`listening to port ${port}...`)
})