https://github.com/thebeaconcrafter/cdn-server
Simple CDN Server
https://github.com/thebeaconcrafter/cdn-server
cdn node
Last synced: 3 months ago
JSON representation
Simple CDN Server
- Host: GitHub
- URL: https://github.com/thebeaconcrafter/cdn-server
- Owner: TheBeaconCrafter
- License: mit
- Created: 2024-11-24T16:03:33.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-11-27T16:50:16.000Z (7 months ago)
- Last Synced: 2025-01-31T19:13:31.010Z (5 months ago)
- Topics: cdn, node
- Language: JavaScript
- Homepage:
- Size: 77.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE.MD
Awesome Lists containing this project
README
# Beacon CDN Server
This is a Node.js-based CDN server that provides file uploads, storage, and retrieval. It features user authentication, public file access with previews, and SSL encryption for secure communication.
## Features
* User authentication using JWT (JSON Web Tokens)
* File uploads with multer
* File storage using MariaDB and the server's file system
* API endpoints for file management (upload, list, delete, download)
* Public file access with previews for images and videos
* SSL encryption for HTTPS## Technologies Used
* Node.js
* Express.js
* MariaDB
* JWT (jsonwebtoken)
* multer
* HTTPS## Installation
1. Clone the repository: `git clone https://github.com/TheBeaconCrafter/cdn-server.git`
2. Install dependencies: `npm install`
3. Configure database connection:
* Create a MariaDB database (e.g., `cdnserver`)
* Create `users` and `files` tables (see SQL statements below)
4. Update settings in `configExample.js` and rename to `config.js`
5. Create a .env file that contains a random string for SYNC_SECRET="your_sync_secret" (see config.js)
6. Configure SSL encryption:
* Obtain SSL certificates (private key, SSL certificate, intermediate certificate)
* Drop them into the folder `ssl` (create if it doesn't exist)
7. Start the server with either `node index.js` or `./start.sh`## Database Setup
**Create users table:**
```sql
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL
);
```
**Create your user account**```sql
INSERT INTO users (username, password) VALUES ('your_username', 'your_password');
```**Create files table:**
```sql
CREATE TABLE files (
id INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
filename VARCHAR(255) NOT NULL,
path VARCHAR(255) NOT NULL,
fileKey VARCHAR(255),
FOREIGN KEY (userId) REFERENCES users(id)
);
```**Create static table**
```sql
CREATE TABLE static (
id INT(11) NOT NULL AUTO_INCREMENT,
folder VARCHAR(255) NOT NULL,
filename VARCHAR(255) NOT NULL,
originalname VARCHAR(255) NOT NULL,
path VARCHAR(255) NOT NULL,
size INT(11) NOT NULL,
createdAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
```## Setup Second Server (not required)
This feature is not fully implemented and testet. Proceed with caution.
Known issues:
- Files deleted on the master are not yet deleted on the backup servers.**If you want to use sync with two servers, set up a DB on the second server:**
```sql
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL
);
```
**Create your user account**```sql
INSERT INTO users (username, password) VALUES ('your_username', 'your_password');
```**Create files table:**
```sql
CREATE TABLE files (
id INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
filename VARCHAR(255) NOT NULL,
path VARCHAR(255) NOT NULL,
fileKey VARCHAR(255),
fileId INT UNIQUE,
FOREIGN KEY (userId) REFERENCES users(id)
);
```## API Endpoints
* **POST /upload:** Uploads a file (requires authentication via token received with /login)
* **GET /files/user/:userId:** Retrieves files for a specific user (requires authentication)
* **DELETE /files/:fileId:** Deletes a file (requires authentication)
* **GET /files/:fileId/download:** Downloads a file (public)
* **GET /files/:fileId/embed:** Embed a file without forcing a download (public)
* **POST /login:** User login
* **GET /public/:fileId:** Public file access with preview and download## Usage
1. Upload files through the `/upload` endpoint after authenticating.
2. Access and manage files using the provided API endpoints.
3. Share files publicly using the `/public/:fileId` endpoint.## Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
## License
This project is licensed under the MIT License (see LICENSE.MD for info).