-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
55 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
app.use(express.json()); | ||
app.use( | ||
express.urlencoded({ | ||
extended: true, | ||
}) | ||
); | ||
|
||
app.use('/health', (req, res) => { | ||
const healthCheck = { | ||
uptime: process.uptime(), | ||
message: 'OK', | ||
timestamp: Date.now(), | ||
}; | ||
try { | ||
res.send(healthCheck); | ||
} catch (error) { | ||
healthCheck.message = error; | ||
res.status(503), send(); | ||
} | ||
}); | ||
|
||
const PORT = '5000' || process.env.PORT; | ||
module.exports = { | ||
app, | ||
PORT, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
require('dotenv').config(); | ||
|
||
DB_URI = process.env.DB_URI; | ||
|
||
const DB_URI = process.env.DB_URI; | ||
|
||
module.exports = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const mongoose = require('mongoose'); | ||
const { DB_URI } = require('./config'); | ||
|
||
const dbConnection = async () => { | ||
await mongoose | ||
.connect(DB_URI, { useNewUrlParser: true, useUnifiedTopology: true }) | ||
.then(() => { | ||
console.log('Database connected successfully!'); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}; | ||
|
||
module.exports = dbConnection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,11 @@ | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const mongoose = require('mongoose'); | ||
const { app, PORT } = require('./app'); | ||
const dbConnection = require('./config/db'); | ||
|
||
const app = express(); | ||
const PORT = '5000' || process.env.PORT; | ||
const { DB_URI } = require('./config/config'); | ||
|
||
mongoose | ||
.connect(DB_URI, { useNewUrlParser: true, useUnifiedTopology: true }) | ||
.then(() => { | ||
console.log('Database connected successfully!'); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
const bootstrap = () => { | ||
app.listen(PORT, () => { | ||
dbConnection(); | ||
console.log(`app is listening on http://localhost:${PORT}..`); | ||
}); | ||
}; | ||
|
||
app.use(cors()); | ||
app.use(express.json()); | ||
app.use( | ||
express.urlencoded({ | ||
extended: true, | ||
}) | ||
); | ||
|
||
app.use('/health', (req, res) => { | ||
const healthCheck = { | ||
uptime: process.uptime(), | ||
message: 'OK', | ||
timestamp: Date.now(), | ||
}; | ||
try { | ||
res.send(healthCheck); | ||
} catch (error) { | ||
healthCheck.message = error; | ||
res.status(503), send(); | ||
} | ||
}); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`app is listening on http://localhost:${PORT}..`); | ||
}); | ||
bootstrap(); |
Empty file.