Skip to content

Commit

Permalink
Boilerplate for getting AWS certs
Browse files Browse the repository at this point in the history
  • Loading branch information
david-rocca committed Oct 22, 2024
1 parent 6379609 commit 5d404e6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ PORT = 3000
LOCAL_KEY=TCF25YM-39C4H6D-KA32EGF-V5XSHN3
RATE_LIMIT_WINDOW_SECONDS=60
RATE_LIMIT_MAX_CONNECTIONS=1000
USE_AWS_CERT_FILE=true
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"port": 27017
},
"development": {
"useAWSCert": false,
"database": "cve_dev",
"host": "localhost",
"port": 27017
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ WORKDIR /home/node/app
RUN npm install --production
COPY --chown=node:node docker/entrypoint.sh /home/node/app/entrypoint.sh
RUN wget https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem /home/node/app/config/global-bundle.pem
RUN echo '{}' > /home/node/app/config/dev.json
RUN echo '{}' > /home/node/app/config/test.json
RUN echo '{}' > /home/node/app/config/staging.json
Expand Down
33 changes: 27 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,35 @@ app.use((req, res, next) => {
res.status(404).json(error.notFound())
})

console.log('Checking for AWS cert file')
const appEnv = process.env.NODE_ENV
var awsCERTFile = false
if (process.env.USE_AWS_CERT) {
awsCERTFile = process.env.USE_AWS_CERT
} else {
awsCERTFile = config.has(`${appEnv}.useAWSCert`) ? config.get(`${appEnv}.useAWSCert`) : false
}

// Connect to MongoDB database
const dbConnectionStr = dbUtils.getMongoConnectionString()
mongoose.connect(dbConnectionStr, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
if (awsCERTFile) {
mongoose.connect(dbConnectionStr, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
ssl: true,
ca: ''
})
} else {
console.log('NOT USING AWS CERT FILE')
mongoose.connect(dbConnectionStr, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
})
}

// database connection
const db = mongoose.connection
Expand Down

0 comments on commit 5d404e6

Please sign in to comment.