File Upload and Hosting Web Server project demonstrates the creation of a REST API-based web server that allows users to upload files, provides information about uploaded files, and hosts the files on a Kubernetes cluster.
- Project Overview
- Getting Started
- API Endpoints
- User Interface
- Continuous Integration and Deployment
- Deploying to Kubernetes
- Future Improvements
- Conclusion
The project aims to create a web server that facilitates file uploading and hosting, providing users with an API to upload files, view file information, and access hosted files. The project comprises several key components:
-
Backend Server: Built using Node.js and Express.js, the backend handles file uploads, metadata storage in MongoDB, and interactions with Azure Blob Storage for file hosting.
-
Frontend Interface: A basic frontend interface is created to demonstrate file upload and file information retrieval via API requests.
-
Azure Blob Storage: Files uploaded by users are stored in Azure Blob Storage, ensuring secure and scalable file hosting.
-
MongoDB: Metadata about uploaded files, including filename, size, and content type, is stored in MongoDB.
-
Docker: Docker images are built for the frontend and backend components to ensure consistency and ease of deployment.
-
Kubernetes: Kubernetes manifest files define the deployment and service configurations for hosting the application on a Kubernetes cluster.
To run the project locally, follow these steps:
-
Clone the GitHub repository:
git clone https://github.com/ssahibsingh/rapidfort-file-server-api.git
-
Navigate to the
frontend
directory and runnpm install
to install frontend dependencies. -
Navigate to the
backend
directory and runnpm install
to install backend dependencies. -
Create an Azure Blob Storage account and obtain the connection string.
-
Set up a MongoDB instance and obtain the connection URI.
-
Create a
.env
file in thebackend
directory with the following environment variables:PORT=8000 AZURE_STORAGE_CONNECTION_STRING=[Azure Blob Storage Connection String] MONGODB_URI=[MongoDB Connection URI]
-
Start the backend server:
npm start
in thebackend
directory. -
Create a
.env.local
file in thefrontend
directory with the following environment variables:NEXT_PUBLIC_BACKEND_URL=`${backend-server-url}/api`
-
Start the frontend server:
npm start
in thefrontend
directory. -
Access the application in your browser at
http://localhost:3000
.
The API provides the following endpoints:
POST /upload
: Uploads a file to Azure Blob Storage and stores metadata in MongoDB.GET /file/:name
: Retrieves metadata for a specific file.GET /download/:name
: Downloads the specified file.
The basic frontend interface allows users to:
- Upload a file.
- View metadata for a specific file.
- Download a file.
GitHub Actions is used for continuous integration and deployment. The following tasks are automated using GitHub Actions:
- Building Docker images for the frontend and backend components.
- Pushing Docker images to Docker Hub.
- Deploying the application to an Azure VM's Kubernetes cluster.
The application is deployed to a Kubernetes cluster using Kubernetes manifest files located in the azure-deployment
directory. The deployment includes the frontend and backend components, along with appropriate service configurations.
To deploy:
- Configure Kubernetes context using Azure credentials.
- Ensure
kubectl
is installed. - Run the GitHub Actions workflow to deploy the application.
- Frontend: https://fileserver.sahibsingh.dev
- Backend: https://fileserver.sahibsingh.dev/api
The "File Upload and Hosting Web Server" project demonstrates the creation of a REST API-based web server, leveraging Azure Blob Storage and MongoDB for file hosting and metadata storage. The integration of Docker and Kubernetes streamlines deployment, ensuring scalability and flexibility.