feat(server): allow customizing server port via SHUMAI_SERVER_PORT

This commit is contained in:
yiling
2026-06-18 10:08:31 +08:00
parent 62d7061cb3
commit a69dd6a660
5 changed files with 37 additions and 20 deletions
+2 -1
View File
@@ -102,11 +102,12 @@ Create a `.env` file in this folder and add the following configuration (which a
DATABASE_URL=postgresql://shumai:shumai_password@localhost:5432/shumai_db?schema=public
BETTER_AUTH_SECRET=ySxs7DxzHDZBbeeHNPEwBuspYwipBqz5Gk5XdBjNhWw=
STORAGE_BACKEND=local
SHUMAI_SERVER_PORT=3000
AWS_ENDPOINT_URL_S3=http://localhost:3000
```
> [!NOTE]
> If you are deploying on a remote server, make sure to change `AWS_ENDPOINT_URL_S3` from `http://localhost:3000` to your server's public IP address or domain name.
> If you are deploying on a remote server, make sure to change `AWS_ENDPOINT_URL_S3` from `http://localhost:3000` to your server's public IP address or domain name. `SHUMAI_SERVER_PORT` defaults to `3000` if not set.
#### Step 4: Run Shumai
+4 -2
View File
@@ -44,10 +44,12 @@ if (process.env.WORKFLOW_EXECUTOR === 'temporal') {
const isProd = process.env.NODE_ENV === 'production'
const port = process.env.SHUMAI_SERVER_PORT ? parseInt(process.env.SHUMAI_SERVER_PORT) : 3000
const server = Bun.serve(
isProd
? {
port: 3000,
port,
maxRequestBodySize: process.env.MAX_REQUEST_BODY_SIZE
? parseInt(process.env.MAX_REQUEST_BODY_SIZE)
: 1024 * 1024 * 1024 * 10, // Default 10GB
@@ -88,7 +90,7 @@ const server = Bun.serve(
},
}
: {
port: 3000,
port,
maxRequestBodySize: process.env.MAX_REQUEST_BODY_SIZE
? parseInt(process.env.MAX_REQUEST_BODY_SIZE)
: 1024 * 1024 * 1024 * 10, // Default 10GB
+23 -14
View File
@@ -15,12 +15,21 @@ Shumai is configured via environment variables. You can define these variables i
---
## Server Config
| Variable | Description | Example / Default |
| :---------------------- | :------------------------------------------------------------------------------------------------ | :---------------- |
| `SHUMAI_SERVER_PORT` | The port on which the Shumai web server will listen. | `3000` (default) |
| `MAX_REQUEST_BODY_SIZE` | Maximum allowed size for request bodies (e.g., for large file uploads). Default is 10GB in bytes. | `10737418240` |
---
## Authentication Config
| Variable | Description | Example / Default |
| :------------------- | :--------------------------------------------------------------------- | :-------------------------------------- |
| `BETTER_AUTH_SECRET` | A secure, random 32-byte secret used to sign session cookies and JWTs. | Generate with `openssl rand -base64 32` |
| `BETTER_AUTH_URL` | The public URL of your Hono backend API. Used for redirect flows. | `http://localhost:3000` |
| Variable | Description | Example / Default |
| :------------------- | :--------------------------------------------------------------------- | :--------------------------------------------------------------- |
| `BETTER_AUTH_SECRET` | A secure, random 32-byte secret used to sign session cookies and JWTs. | Generate with `openssl rand -base64 32` |
| `BETTER_AUTH_URL` | The public URL of your Hono backend API. Used for redirect flows. | `http://localhost:3000` (respects `SHUMAI_SERVER_PORT` fallback) |
---
@@ -28,16 +37,16 @@ Shumai is configured via environment variables. You can define these variables i
Shumai supports storing files locally or on S3-compatible endpoints.
| Variable | Description | Example / Default |
| :------------------------- | :------------------------------------------------------------------------------------------------ | :-------------------------------- |
| `STORAGE_BACKEND` | Storage type. Use `local` for local file system storage, or `s3` for S3-compatible cloud storage. | `local` (default) or `s3` |
| `AWS_ENDPOINT_URL_S3` | Custom endpoint for S3 storage. Must change to public domain/IP if deploying remotely. | `http://localhost:3000` (default) |
| `S3_BUCKET` | S3 bucket name. | `shumai` (default) |
| `S3_ACCESS_KEY_ID` | Access key credentials for S3. | `minioadmin` (default) |
| `S3_SECRET_ACCESS_KEY` | Secret key credentials for S3. | `minioadmin` (default) |
| `S3_REGION` | S3 storage region. | `auto` (default) |
| `S3_USE_SSL` | Set to `true` to use HTTPS for S3 endpoints. | `false` (default) |
| `PRESIGNED_URL_EXPIRES_IN` | Number of hours for which generated presigned download/upload links are valid. | `5` (default) |
| Variable | Description | Example / Default |
| :------------------------- | :------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------- |
| `STORAGE_BACKEND` | Storage type. Use `local` for local file system storage, or `s3` for S3-compatible cloud storage. | `local` (default) or `s3` |
| `AWS_ENDPOINT_URL_S3` | Custom endpoint for S3 storage. Must change to public domain/IP if deploying remotely. | `http://localhost:3000` (respects `SHUMAI_SERVER_PORT` fallback) |
| `S3_BUCKET` | S3 bucket name. | `shumai` (default) |
| `S3_ACCESS_KEY_ID` | Access key credentials for S3. | `minioadmin` (default) |
| `S3_SECRET_ACCESS_KEY` | Secret key credentials for S3. | `minioadmin` (default) |
| `S3_REGION` | S3 storage region. | `auto` (default) |
| `S3_USE_SSL` | Set to `true` to use HTTPS for S3 endpoints. | `false` (default) |
| `PRESIGNED_URL_EXPIRES_IN` | Number of hours for which generated presigned download/upload links are valid. | `5` (default) |
---
+6 -2
View File
@@ -15,9 +15,13 @@ export const auth = betterAuth({
},
secret: process.env.BETTER_AUTH_SECRET,
// eslint-disable-next-line @typescript-eslint/naming-convention
baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3000',
baseURL:
process.env.BETTER_AUTH_URL || `http://localhost:${process.env.SHUMAI_SERVER_PORT || '3000'}`,
basePath: '/api/auth',
trustedOrigins: ['http://localhost:3000', 'http://127.0.0.1:3000'],
trustedOrigins: [
`http://localhost:${process.env.SHUMAI_SERVER_PORT || '3000'}`,
`http://127.0.0.1:${process.env.SHUMAI_SERVER_PORT || '3000'}`,
],
advanced: {
disableCSRFCheck: true,
},
+2 -1
View File
@@ -451,7 +451,8 @@ export class LocalStorageService implements S3Service {
}
const storageBackend = process.env.STORAGE_BACKEND || 'local'
const s3Endpoint = process.env.AWS_ENDPOINT_URL_S3 || 'http://localhost:3000'
const s3Endpoint =
process.env.AWS_ENDPOINT_URL_S3 || `http://localhost:${process.env.SHUMAI_SERVER_PORT || '3000'}`
export const s3Service: S3Service =
storageBackend === 's3'