pstream-docs/pages/backend/deploy.mdx
Pas e82d73de3e
Some checks failed
docs-deploy / Build (push) Has been cancelled
Linting and Testing / Run Linters (push) Has been cancelled
docs-deploy / deploy (push) Has been cancelled
Merge pull request #6 from dumbutdumber/master
Fixed self host a bit
2025-12-26 23:55:01 -07:00

170 lines
6.1 KiB
Text

---
title: 'Deploy'
---
# Deploying the backend
The only officially recognized hosting method is through Docker (or similar container runtimes). It can be scaled horizontally to all your heart's content and is the safest way to host the backend.
For configuration, check out the [configuration reference](./configuration.mdx).
## Method 1 - Cloudflare Deployment (Free + Easy)
**Prerequisites**
- A [Cloudflare](https://cloudflare.com) account
- A [GitHub](https://github.com) account
<Steps>
<Steps.Step>
Create a Cloudflare Worker for the backend In the [Cloudflare
Dashboard](https://dash.cloudflare.com/) go to the sidebar, then click
"Compute & AI" > "Workers and Pages"
</Steps.Step>
<Steps.Step>
Select "Create application" then click "Continue with GitHub"
</Steps.Step>
<Steps.Step>
If needed, link your GitHub account to your Cloudflare account.
</Steps.Step>
<Steps.Step>
Go to the backend [repository](https://github.com/p-stream/backend) click
Star, to Star it :P then Fork the project by clicking Fork, then Create
Fork.
</Steps.Step>
<Steps.Step>
In the Cloudflare dashboard select the GitHub repository you set for the
backend, it should set the build command as `npm run build` and deploy
command as `node .output/server/index.mjs`
</Steps.Step>
<Steps.Step>
Backend uses PostgreSQL as our database, so you need somewhere to host. I
personally recommend [Neon](https://neon.com/) as they have a perfectly fine
free tier. For larger deployments, it can be quite expensive, so have a
backup strategy if you get a lot of users.
</Steps.Step>
<Steps.Step>
In the Neon dashboard click create project, give it a name, then click
Connect to your Database. It should give you a line like this: ``` psql
'postgresql://neondb_owner:RANDOMSTUFFHERE@MORERANDOMSTUFF.c-2.us-east-1.aws.neon.tech/neondb?sslmode=require&channel_binding=require'
``` Copy the url including the `postgresql://` for the next step.
</Steps.Step>
<Steps.Step>
Set your Environment Variables. In the Cloudflare dashboard, go to your
worker, go to settings, then click "Configure API token and other runtime
variables" Now set your variables:
- CRYPTO_SECRET: Generate a random 32
character string and set that as the value
- DATABASE_URL: The long
postgres:// string from earlier.
- META_NAME: Whatever you want the name to be, users will see it when they sign up
- META_DESCRIPTION: The description for your instance
</Steps.Step>
<Steps.Step>Now you should be done! Have fun with your new backend, and if you would like, [Star Backend on GitHub](https://github.com/p-stream/backend)</Steps.Step>
</Steps>
## Method 2 - Docker Deployment
This method provides a straightforward setup with minimal configuration. For more extensive customization, see the [Configuration Reference](./configuration.mdx).
**Prerequisites**
- **Docker:** If you don't have Docker installed, download it from the official website: [Docker installation](https://www.docker.com/get-started)
**Setup**
<Steps>
<Steps.Step>
**Create `docker-compose.yml`:**
```yaml
services:
postgres:
image: postgres
environment:
POSTGRES_USER: pstream_user
POSTGRES_DB: pstream
POSTGRES_PASSWORD: YourPasswordHere
ports:
- "5432:5432"
networks:
- p-stream-network
p-stream:
image: ghcr.io/dumbutdumber/backend:latest
environment:
DATABASE_URL: postgresql://pstream_user:YourPasswordHere@postgres:5432/pstream
CRYPTO_SECRET: 32CharacterLongStringHere
META_NAME: unofficial-backend
ports:
- "80:80"
depends_on:
- postgres
networks:
- p-stream-network
networks:
p-stream-network:
driver: bridge
```
**Important:**
* Replace `YourPasswordHere` with your secure database password.
* Generate a strong session secret and replace `32CharacterLongStringHere`.
</Steps.Step>
<Steps.Step>
**Start the Backend:** Open a terminal in the directory containing `docker-compose.yml` and execute:
```bash
docker-compose up -d
```
</Steps.Step>
</Steps>
### Accessing Your Backend
Your backend should be accessible on `(YourPrivateIP):80`. To share it outside your local network, you'll need to configure port forwarding or cloudflared tunnel.
## Method 3 - Railway (Easy)
Railway offers a 30-day free trial that includes a one-time $5 credit. After the trial, you receive $1 in usage credits for free each month.
[![Deploy on Railway](https://railway.com/button.svg)](https://railway.com/deploy/pstreambackend?referralCode=zvXFZF)
<Steps>
<Steps.Step>
Login to your [Railway](https://railway.app) account if you have one,
otherwise create one [here](https://railway.app/login). - If you are signing
up, then verify your account by clicking the link in the email Railway sends
you. Ensure you setup your server location [here](https://railway.com/workspace)
to the closest one possible.
</Steps.Step>
<Steps.Step>
Click the [`Deploy on
Railway`](https://railway.com/deploy/pstreambackend?referralCode=zvXFZF)
button above.
</Steps.Step>
<Steps.Step>Click on configure For the one that says Backend.</Steps.Step>
<Steps.Step>
Fill in the required variable META_NAME the rest are optional and can be set
later on.
</Steps.Step>
<Steps.Step>
The `Deploy` button at the bottom of the template should be active, click on
it.
</Steps.Step>
<Steps.Step>
Once the `Backend` service has deployed, copy the URL from the `Deployments`
page. (Might take a second for it to be available after the service has
deployed)
</Steps.Step>
<Steps.Step>
Congratulations! You have deployed the backend, you can now [set up the
client](../self-hosting/use-backend.mdx).
</Steps.Step>
</Steps>