-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/SAINIAbhishek/nodejs_auth-api
- Loading branch information
Showing
13 changed files
with
226 additions
and
17 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,48 @@ | ||
# Add any directories, files, or patterns you don't want to be tracked by version control | ||
.idea | ||
|
||
# ignore vs code project config files | ||
.vscode | ||
.vs | ||
|
||
# ignore logs | ||
logs | ||
*.log | ||
|
||
# ignore 3rd party lib | ||
node_modules | ||
|
||
# Ignore built files | ||
build/ | ||
dist/ | ||
|
||
# ignore test converage | ||
coverage/ | ||
|
||
# git | ||
.gitignore | ||
.git/ | ||
|
||
.DS_Store | ||
|
||
# docker | ||
dockerfile | ||
.dockerignore | ||
|
||
# Environment varibles | ||
.env | ||
|
||
# Ignore local development files | ||
tmp/ | ||
temp/ | ||
|
||
# Ignore npm debug files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Ignore output from TypeScript compiler | ||
*.tsbuildinfo | ||
|
||
# Ignore eslint cache | ||
.eslintcache |
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
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,61 @@ | ||
services: | ||
mongodb: | ||
# To create this service, Compose will pull the mongo | ||
image: mongo:7.0.4 | ||
# a custom name for the MongoDB container | ||
container_name: mongo | ||
# Configures the container to restart automatically. | ||
restart: always | ||
# Volumes to persist data and initialize MongoDB | ||
volumes: | ||
# The named volume dbdata will persist the data stored in Mongo’s default data directory, /data/db. | ||
# This will ensure that you don’t lose data in cases where you stop or remove containers. | ||
- dbdata:/data/db | ||
healthcheck: | ||
test: | ||
['CMD', 'mongosh', '--quiet', '--eval', "db.adminCommand('ping').ok"] | ||
interval: 1m | ||
timeout: 10s | ||
retries: 3 | ||
start_period: 30s | ||
|
||
# To build node image | ||
api: | ||
# This defines the configuration options, including the context and dockerfile, | ||
# that will be applied when Compose builds the application image. | ||
build: | ||
# This defines the build context for the image build | ||
context: ./ | ||
args: | ||
NODE_ENV: production | ||
# This is the name we’ll use to refer to this image in Docker commands or to push to a Docker registry. | ||
image: sainiabhishek/nodejs_auth-api:1.1.0 | ||
container_name: api | ||
env_file: .env | ||
restart: always | ||
environment: | ||
MONGO_URI: mongodb://mongo:27017/ | ||
MONGO_DB_HOST: mongo | ||
TOKEN_ISSUER: api.prod.saini.com | ||
TOKEN_AUDIENCE: prod.saini.com | ||
FRONTEND_RESET_URL: http://localhost:3000/ | ||
CORS_URL: http://localhost:3000 | ||
MAILTRAP_EMAIL_ENV: testing | ||
ports: | ||
- ${PORT}:3001 | ||
depends_on: | ||
mongodb: | ||
condition: service_healthy | ||
healthcheck: | ||
test: ['CMD', 'curl', '-f', 'http://localhost:3001/api/v1/healthcheck'] | ||
interval: 1m | ||
timeout: 10s | ||
retries: 3 | ||
start_period: 30s | ||
|
||
# Our top-level volumes key defines the volumes dbdata. | ||
# When Docker creates volumes, the contents of the volume are stored in a part of the host filesystem, /var/lib/docker/volumes/, that’s managed by Docker. | ||
# The contents of each volume are stored in a directory under /var/lib/docker/volumes/ and get mounted to any container that uses the volume. | ||
# In this way, the data that our users will create will persist in the dbdata volume even if we remove and recreate the db container. | ||
volumes: | ||
dbdata: |
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,59 @@ | ||
# Stage 1: Build Stage | ||
FROM node:20.17.0-slim AS build | ||
|
||
# Display build information | ||
RUN echo "!!!!!! Building node application API image !!!!!!" | ||
|
||
# Set the working directory inside the build container | ||
WORKDIR /app | ||
|
||
# Copy package.json and package-lock.json to the working directory | ||
COPY package*.json ./ | ||
|
||
# We are installing the same version that we have in the locally | ||
RUN npm ci | ||
|
||
# Copy the rest of the application code to the working directory | ||
COPY . . | ||
|
||
# Build the application | ||
RUN npm run build | ||
|
||
# Remove unnecessary files after the build | ||
RUN rm -rf \ | ||
node_modules/.bin \ | ||
src \ | ||
*.md \ | ||
.eslintignore \ | ||
.prettierignore \ | ||
tsconfig.json \ | ||
.prettierrc \ | ||
.eslintrc.json | ||
|
||
# Stage 2: Production Stage | ||
FROM node:20.17.0-slim AS production | ||
|
||
# Install curl | ||
RUN apt-get update && apt-get install -y curl | ||
|
||
# Argument and environment variable for production mode | ||
ARG NODE_ENV | ||
ENV NODE_ENV=${NODE_ENV} | ||
|
||
# Set the working directory inside the final container | ||
WORKDIR /app | ||
|
||
# Copy only the production dependencies and built application from the build stage | ||
COPY --from=build /app/package*.json ./ | ||
COPY --from=build /app/node_modules ./node_modules | ||
COPY --from=build /app/build ./build | ||
COPY --from=build /app/.env.example ./.env | ||
|
||
# Remove .env.example file | ||
RUN rm -rf .env.example | ||
|
||
# Expose the application port | ||
EXPOSE 3001 | ||
|
||
# Define the command to run your application | ||
CMD [ "npm", "run", "serve" ] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,13 @@ | ||
import asyncHandler from 'express-async-handler'; | ||
import { SuccessResponse } from '../middleware/ApiResponse'; | ||
|
||
class HealthCheckController { | ||
|
||
checkHealth = asyncHandler(async (req, res) => { | ||
new SuccessResponse('The API is up and running. Health check is passed.', {}).send(res); | ||
}); | ||
|
||
} | ||
|
||
|
||
export default new HealthCheckController(); |
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
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,12 @@ | ||
import express from 'express'; | ||
import HealthCheckController from '../../controllers/HealthCheckController'; | ||
|
||
const router = express.Router(); | ||
|
||
router | ||
.route('/') | ||
.get( | ||
HealthCheckController.checkHealth | ||
); | ||
|
||
export default router; |
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
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