Skip to content

Commit

Permalink
prod vs devlop
Browse files Browse the repository at this point in the history
Signed-off-by: Deepanshu Yadav <[email protected]>
  • Loading branch information
deepanshu-yadav committed Nov 27, 2023
1 parent 1123da3 commit 88cbeec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ else {
console.log("The string is \n");
console.log(config.mongo_db.connection_string);

const STATE = "DEVELOPMENT";
config.state = STATE;
module.exports = config;
2 changes: 2 additions & 0 deletions docker/nodejs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ WORKDIR /usr/src/app
# Clone the Git repository
RUN git clone https://github.com/deepanshu-yadav/devopsprojects23.git .

RUN -i "s/DEVELOPMENT/${STATE}/g" ./configure.js

# Install app dependencies
RUN npm install

Expand Down
20 changes: 15 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ const mongoose = require('mongoose');
app.use(express.json())
app.use(express.urlencoded({extended: false}))

// Configuration
var config = require('./configure');
conn_string = config.mongo_db.connection_string
console.log("Connecting to %s", conn_string)
mongoose.set("strictQuery", false)
STATE = config.state;

//routes

app.get('/', (req, res) => {
res.send('Hello NODE API')
})

app.get('/blog', (req, res) => {
res.send('Hello Blog, My name is Deepanshu')
if (STATE == "DEVELOPMENT") {
res.send('Hello We are in Development state.');
}
else
{
res.send('Hello We are in Production state.');
}
})

app.get('/products', async(req, res) => {
Expand Down Expand Up @@ -83,10 +96,7 @@ app.delete('/products/:id', async(req, res) =>{
})


var config = require('./configure');
conn_string = config.mongo_db.connection_string
console.log("Connecting to %s", conn_string)
mongoose.set("strictQuery", false)


async function start() {
try{
Expand Down

0 comments on commit 88cbeec

Please sign in to comment.