-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from vratix-dev/feature/misc-docs
FEATURE: Misc docs
- Loading branch information
Showing
14 changed files
with
307 additions
and
57 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
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,81 @@ | ||
--- | ||
title: Deployment | ||
description: Deployment Guide | ||
--- | ||
|
||
Deploy your backend service locally or on your cloud service of choice using Docker or directly on your host machine. | ||
|
||
## With Docker | ||
|
||
If Docker is enabled for your project, a `docker-compose.yaml` file will be available with all necessary container configurations. | ||
Ensure Docker Engine and Docker Compose are installed. | ||
|
||
### localhost | ||
|
||
**Step 1:** Configure your `.env` file with the necessary environment variables. | ||
|
||
**Step 2:** Run the following command to start the service: | ||
|
||
```bash | ||
docker compose up -d --build | ||
``` | ||
|
||
This command performs several actions: | ||
|
||
1. **Copies your service files** to the `backend` container. | ||
2. **Builds the project** in the container with `tsup --watch`. | ||
3. **Runs the service** within the container, monitoring for changes and restarting as needed. Refer to the `docker:serve` command in `package.json`. | ||
4. **Builds and runs other containers** (e.g., `postgres` or `ingress-proxy`) as specified in `docker-compose.yaml`. | ||
|
||
### Staging/Production | ||
|
||
> **Note:** Using a prebuilt container image is recommended for cloud deployments. This guide outlines deployment without a prebuilt image. | ||
If you are using a cloud-provisioned DB resource, you might want to remove any DB containers in staging/production by updating the `include` property in your `docker-compose.yaml`. | ||
|
||
**Step 1:** Set `NODE_ENV=production` in your `.env` file to target the production build stage (see `docker-compose.yaml` on line 7). | ||
|
||
**Step 2:** Clone your project to the host server and install any required dependencies, such as Docker Compose and `pnpm`. | ||
|
||
**Step 3:** Configure your production `.env` with the appropriate variables. | ||
|
||
**Step 4 (Optional):** Configure an NGINX proxy for SSL and to handle incoming requests. Refer to the [NGINX guide](/docs/nginx). | ||
|
||
**Step 5:** Run the following command to build and start the Docker services: | ||
|
||
```bash | ||
docker compose up -d --build | ||
``` | ||
|
||
## Without Docker | ||
|
||
Running the service without Docker simplifies the process, though you may still need a DB container for local development or an NGINX proxy for staging/production. | ||
|
||
### localhost | ||
|
||
**Step 1:** Configure your `.env` file with required local environment variables. | ||
|
||
**Step 2:** Use the following command to start the service: | ||
|
||
```bash | ||
npm run dev:local | ||
``` | ||
|
||
This will: | ||
1. Build the project in watch mode using `tsup --watch` | ||
2. Run the service, automatically restarting on file changes. See the `local:serve` command in `package.json` for configuration. | ||
|
||
### Staging/Production | ||
|
||
**Step 1:** Clone your project to the production server. | ||
|
||
**Step 2:** Configure your production `.env` with the appropriate variables. | ||
|
||
**Step 3 (Optional):** Configure a reverse proxy (e.g., NGINX) to handle SSL and incoming requests. Refer to the [NGINX guide](/docs/nginx) for setup. | ||
|
||
**Step 4:** Run the following commands to build and start the service: | ||
|
||
```bash | ||
npm run build:prod | ||
npm run prod:serve | ||
``` |
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,92 @@ | ||
--- | ||
title: NGINX Configuration Guide | ||
description: Configure an NGINX web proxy for your backend service with SSL support | ||
--- | ||
|
||
Our Node.js template includes a minimal [NGINX configuration](https://github.com/vratix-dev/api-library/tree/17826bff71a99fc1e74860f3acc9129e27b3dbec/templates/node-ts/nginx) | ||
that works out-of-the-box for most deployments, but you can expand it as needed. | ||
|
||
The default template does not include SSL support. Below are detailed instructions on setting up SSL with Let's Encrypt. | ||
|
||
## SSL Setup (Optional) | ||
|
||
> SSL certificates are generated on the host and then mounted into the NGINX Docker container. | ||
### 1. Install Certbot and Generate SSL Certificates | ||
|
||
1. **Install Certbot** (Let's Encrypt client) on your host if it’s not already installed: | ||
|
||
```bash | ||
sudo apt install certbot | ||
``` | ||
|
||
2. **Generate SSL certificates** for your domain. Replace `yourdomain.com` with your actual domain name: | ||
|
||
```bash /yourdomain.com/ | ||
sudo certbot certonly --standalone -d yourdomain.com -d www.yourdomain.com | ||
``` | ||
|
||
Certificates will be stored in `/etc/letsencrypt/live/yourdomain.com/`. | ||
|
||
### 2. Update `nginx.conf` for SSL | ||
|
||
Modify your `nginx.conf` to enable SSL: | ||
|
||
1. **Add an HTTPS server block** in `nginx.conf`, configured as follows: | ||
```nginx /yourdomain.com/ | ||
server { | ||
listen 443 ssl; | ||
server_name yourdomain.com; | ||
ssl_certificate /etc/ssl/certs/fullchain.pem; | ||
ssl_certificate_key /etc/ssl/certs/privkey.pem; | ||
ssl_protocols TLSv1.2 TLSv1.3; | ||
ssl_prefer_server_ciphers on; | ||
location / { | ||
proxy_pass http://backend:3000; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
} | ||
} | ||
``` | ||
2. **Add an HTTP to HTTPS redirect block** (optional): | ||
```nginx /yourdomain.com/ | ||
server { | ||
listen 80; | ||
server_name yourdomain.com; | ||
return 301 https://$host$request_uri; | ||
} | ||
``` | ||
|
||
### 3. Mount Certificates in Docker | ||
|
||
Ensure SSL certificates are available to the NGINX container by mounting them in `docker-compose.yml`. | ||
Replace `yourdomain.com` with your domain name: | ||
|
||
```yaml /yourdomain.com/ | ||
services: | ||
nginx: | ||
volumes: | ||
- ./etc/letsencrypt/live/yourdomain.com:/etc/ssl/certs:ro | ||
``` | ||
### 4. Automate SSL Renewal | ||
1. **Open your crontab** to add an automated renewal job: | ||
```bash | ||
sudo crontab -e | ||
``` | ||
|
||
2. **Add the renewal command** to run daily at 3 AM (or adjust the schedule as desired): | ||
|
||
```bash | ||
0 3 * * * certbot renew --quiet && docker compose -f /path-to-your-project/docker-compose.yml restart nginx | ||
``` | ||
|
||
This setup will check for certificate renewal daily and restart NGINX if renewal occurs. |
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
--- | ||
title: Overview | ||
description: Easy-to-use, open-source modules that implement common API logic for seamless integration into Node.js APIs. | ||
description: Easy-to-use, open-source modules that implement common API logic to simplify backend development | ||
--- | ||
|
||
We created this library of reusable API modules to streamline API development. As backend developers, we often found ourselves doing repetitive work or copying outdated code from old projects and inconsistent online sources. | ||
We created this library of reusable API modules to simplify API development because we were wasting too much time setting up basic functionality and researching the latest backend best practices. | ||
We wanted a repository of high-quality API modules we can reuse, copy and paste into our projects and have a working backend in seconds. | ||
|
||
This led us to build a high-quality repository of reusable API modules that address common functionality used in every backend service. | ||
In the age of AI code assistants, these modules remain reliably crafted by developers, following best practices with minimal assumptions. | ||
This makes it easy for any developer to integrate these modules into any API project with flexibility. | ||
In the age of AI code assistants, the modules are reliably built by us, following best practices with minimal assumptions | ||
so developers can integrate them into any API project and have full ownership and control of their codebase. | ||
|
||
Currently, the modules support **Express.js**, and we’re actively working to extend compatibility with other backend languages and popular Node.js frameworks. | ||
Currently, the modules work for **Express.js**, however, we’re actively working to extend compatibility with other backend languages and popular Node.js frameworks. | ||
We would be more than happy for you to contribute and help us achieve this faster. | ||
|
||
> **NOTE:** This isn’t just another package; it’s a source code repository you can copy and use — your code, your way. | ||
These modules are designed to serve as a solid foundation for API development, so feel free to adapt them to fit your unique needs. | ||
> This isn’t just another package; it’s a source code repository you can copy and use — your code, your way. | ||
The modules are designed to be a solid foundation for any API service, **you should customize them to fit your unique needs**. | ||
|
||
**We recommend using our CLI** to import modules into your codebase. The CLI automates file placement, manages external dependencies, sets up database repositories, and resolves module imports. | ||
**We recommend using our CLI** to import modules into your codebase. It automates file placement, manages external dependencies, sets up database repositories and migrations, and resolves module imports. | ||
|
||
Stop reinventing the wheel. Start innovating where it counts. |
Oops, something went wrong.