FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
homebase-lite-backend/server.js at main · dOrgTech/homebase-lite-backend · GitHub
dOrgTech
/
homebase-lite-backend
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
2
Code
Issues
1
Pull requests
5
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
homebase-lite-backend
/
server.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (57 loc) · 1.72 KB
Breadcrumbs
homebase-lite-backend
/
server.js
Copy path
File metadata and controls
70 lines (57 loc) · 1.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
const
express
=
require
(
"express"
)
;
const
cors
=
require
(
"cors"
)
;
const
mongoose
=
require
(
'mongoose'
)
;
const
{
securePayload
}
=
require
(
"./middlewares"
)
;
require
(
"dotenv"
)
.
config
(
{
path
:
"./config.env"
}
)
;
// get driver connection
const
dbo
=
require
(
"./db/conn"
)
;
const
app
=
express
(
)
;
const
port
=
process
.
env
.
PORT
||
5000
;
app
.
use
(
cors
(
{
origin
:
"*"
,
}
)
)
;
app
.
use
(
express
.
json
(
)
)
;
// Apply XSS protection middleware globally
app
.
use
(
securePayload
)
;
// Include Swagger route at the base URL
app
.
use
(
'/'
,
require
(
'./routes/swagger'
)
)
;
// Other routes are included after the Swagger route
app
.
use
(
require
(
"./routes/daos"
)
)
;
app
.
use
(
require
(
"./routes/polls"
)
)
;
app
.
use
(
require
(
"./routes/tokens"
)
)
;
app
.
use
(
require
(
"./routes/choices"
)
)
;
app
.
use
(
require
(
"./routes/blocks"
)
)
;
app
.
use
(
require
(
"./routes/aci"
)
)
;
app
.
listen
(
port
,
async
(
)
=>
{
// perform a database connection when server starts
try
{
dbo
.
connectToServer
(
)
;
}
catch
(
error
)
{
console
.
error
(
error
)
;
}
console
.
log
(
`Server is running on port:
${
port
}
`
)
;
}
)
;
function
getMongoDBDatabaseName
(
url
)
{
const
dbNameMatch
=
url
.
match
(
/
\/
(
[
^
/
?
]
+
)
(
\?
|
$
)
/
)
;
return
dbNameMatch
?
dbNameMatch
[
1
]
:
null
;
}
const
connectToMongoDB
=
async
(
)
=>
{
try
{
let
connUrl
=
process
.
env
.
ATLAS_URI
;
const
database
=
getMongoDBDatabaseName
(
connUrl
)
;
if
(
!
database
)
{
const
urlParts
=
connUrl
.
split
(
'?'
)
;
connUrl
=
`
${
urlParts
[
0
]
}
Lite?
${
urlParts
[
1
]
||
''
}
`
;
}
console
.
log
(
connUrl
)
;
await
mongoose
.
connect
(
connUrl
)
;
console
.
log
(
'Connected to MongoDB using Mongoose'
)
;
}
catch
(
error
)
{
console
.
error
(
'Error connecting to MongoDB:'
,
error
)
;
process
.
exit
(
1
)
;
}
}
;
// Call the function to connect to MongoDB
connectToMongoDB
(
)
;
Back
|
FazBrowse Home
|
New Git URL