Welcome to the backend API for Aftermath Archive, an Incident Management web application.
This backend is hosted on Render and integrates with the frontend hosted on Netlify.
It utilizes a MongoDB database, managed through MongoDB Atlas, to store and retrieve application data.
- Frontend URL:
aftermath-archive.xyz
- Backend URL:
api.aftermath-archive.xyz
https://github.com/Aftermath-Archive/frontend
https://github.com/Aftermath-Archive/docker-deployment
API endpoint documentation is available here.
For students, or teachers who are viewing this repo in the context of the Coder Academy final assignment I have created a separate branch 'project-submission' available here.
This branch captures the projects state at time of submission while future work is undergone on the project.
This guide outlines the steps to deploy the backend of the Aftermath Archive application to a production environment. The backend is built using Node.js and Express, and it can be deployed to a cloud hosting provider such as AWS, Heroku, Render, or DigitalOcean.
- Node.js: Ensure you have Node.js (version 16.x or higher) installed.
- Backend Source Code: Access to the GitHub repository containing the backend code.
- Cloud Hosting Account: An account with a hosting provider like Heroku, AWS, Render, or DigitalOcean.
- Database: Ensure your MongoDB database is accessible (e.g., MongoDB Atlas or a self-hosted MongoDB instance).
- Environment Variables: Have the necessary environment variables ready, such as database connection strings, JWT secrets, and API keys.
git clone https://github.com/Aftermath-Archive/backend
cd backend
Run the following command to install the required dependencies:
npm install
Create a .env file in the root directory based on the existing .env.example
and define the required variables:
DATABASE_URL=your-mongodb-connection-string
JWT_SECRET_KEY=your-jwt-secret
Note: Replace the placeholder values with actual values.
Start the backend server to ensure it works as expected:
npm run start
Visit http://localhost:PORT
in your browser or use an API client like Postman or Bruno to test endpoints.
-
Create an account and log in to Render.
-
Click New Web Service and connect your GitHub repository.
-
Configure the service:
- Environment: Node.js
- Build Command: npm install
- Start Command: npm run start
-
Add environment variables in the “Environment” section.
-
Deploy the application. Render will build and start your backend automatically.
-
Confirm Docker Installed Download available for Docker for Mac, Windows, and Linux.
-
Cloud Hosting (Optional)
If deploying to a cloud service, ensure you have an instance/server on platforms such as:
- AWS EC2
- Azure Virtual Machine
- Google Cloud Platform Compute Engine
- Digital Ocean
- Render
- Railway
- etc
-
Build the Docker Image
Run the` following command in the root of the backend project:
docker build -t aftermath-archive-backend .
-
Run the container locally
To test the container on your local machine, run:
docker run --env-file .env -p 4000:4000 aftermath-archive-backend
--env-file .env
: Loads the environment variables from .env.-p 4000:4000
: Maps port 4000 of the container to 4000 on your local machine.
For easier setup, a docker-compose.yml
file for both front and backend is available here.
- Double-check the
DATABASE_URL
environment variable and ensure the database allows connections from the server.
- Configure CORS in the server.js file.
By following these steps, you will have a fully deployed and functional backend for the Aftermath Archive application.
This application uses Passport.js for handling authentication. The core configuration for Passport is located in src/config/passport.js
, where strategies are defined. By default, the app is configured to support JWT authentication.
Passport makes it easy to integrate additional authentication strategies such as Google, GitHub, Facebook, Twitter, and more. You can add your own strategies by modifying the passport.js file and installing the relevant Passport strategy packages. For a full list of supported strategies and documentation, visit the official Passport.js website.
If you want to extend the app to support OAuth or Single Sign-On (SSO), Passport provides a flexible way to scale authentication without rewriting core logic.
To enhance the security and user experience, we plan to implement a refresh token strategy. This will allow:
- Short-lived Access Tokens (e.g., 15 minutes) for improved security.
- Long-lived Refresh Tokens (e.g., 7 days) to issue new access tokens without requiring the user to log in again.
- Token Rotation to mitigate the risk of compromised refresh tokens.
This enhancement would involve:
- Issuing refresh tokens during login.
- Creating a
/refresh-token
endpoint to generate new access tokens. - Securely storing refresh tokens and invalidating them upon logout.
This feature is beyond the current project scope but would improve scalability and security for production use.