Merge pull request #223 from getmaxun/allow-origins
feat: dynamic public url
This commit is contained in:
11
ENVEXAMPLE
11
ENVEXAMPLE
@@ -9,14 +9,19 @@ DB_PORT=5432 # Port for PostgreSQL (default: 5432)
|
||||
ENCRYPTION_KEY=f4d5e6a7b8c9d0e1f23456789abcdef01234567890abcdef123456789abcdef0 # Key for encrypting sensitive data (passwords and proxies)
|
||||
MINIO_ENDPOINT=minio # MinIO endpoint in Docker
|
||||
MINIO_PORT=9000 # Port for MinIO (default: 9000)
|
||||
MINIO_CONSOLE_PORT=9001 # Web UI Port for MinIO (default: 9001)
|
||||
MINIO_ACCESS_KEY=minio_access_key # MinIO access key
|
||||
MINIO_SECRET_KEY=minio_secret_key # MinIO secret key
|
||||
REDIS_HOST=redis # Redis host in Docker
|
||||
REDIS_PORT=6379 # Redis port (default: 6379)
|
||||
|
||||
# Backend URLs
|
||||
BACKEND_URL=http://localhost:8080 # Internal URL for backend service
|
||||
VITE_BACKEND_URL=http://localhost:8080 # URL used by frontend to connect to backend
|
||||
# Backend and Frontend URLs and Ports
|
||||
BACKEND_PORT=8080 # Port to run backend on. Needed for Docker setup
|
||||
FRONTEND_PORT=5173 # Port to run frontend on. Needed for Docker setup
|
||||
BACKEND_URL=http://localhost:8080 # URL on which the backend runs. You can change it based on your needs.
|
||||
PUBLIC_URL=http://localhost:5173 # URL on which the frontend runs. You can change it based on your needs.
|
||||
VITE_BACKEND_URL=http://localhost:8080 # URL used by frontend to connect to backend. It should always have the same value as BACKEND_URL
|
||||
VITE_PUBLIC_URL=http://localhost:5173 # URL used by backend to connect to frontend. It should always have the same value as PUBLIC_URL
|
||||
|
||||
# Optional Google OAuth settings for Google Sheet Integration
|
||||
GOOGLE_CLIENT_ID=your_google_client_id
|
||||
|
||||
@@ -77,8 +77,12 @@ You can access the frontend at http://localhost:5173/ and backend at http://loca
|
||||
|
||||
| Variable | Mandatory | Description | If Not Set |
|
||||
|-----------------------|-----------|----------------------------------------------------------------------------------------------|--------------------------------------------------------------|
|
||||
| `BACKEND_PORT` | Yes | Port to run backend on. Needed for Docker setup | Default value: 8080 |
|
||||
| `FRONTEND_PORT` | Yes | Port to run frontend on. Needed for Docker setup | Default value: 5173 |
|
||||
| `BACKEND_URL` | Yes | URL to run backend on. | Default value: http://localhost:8080 |
|
||||
| `VITE_BACKEND_URL` | Yes | URL used by frontend to connect to backend | Default value: http://localhost:8080 |
|
||||
| `PUBLIC_URL` | Yes | URL to run frontend on. | Default value: http://localhost:5173 |
|
||||
| `VITE_PUBLIC_URL` | Yes | URL used by backend to connect to frontend | Default value: http://localhost:5173 |
|
||||
| `JWT_SECRET` | Yes | Secret key used to sign and verify JSON Web Tokens (JWTs) for authentication. | JWT authentication will not work. |
|
||||
| `DB_NAME` | Yes | Name of the Postgres database to connect to. | Database connection will fail. |
|
||||
| `DB_USER` | Yes | Username for Postgres database authentication. | Database connection will fail. |
|
||||
@@ -88,6 +92,7 @@ You can access the frontend at http://localhost:5173/ and backend at http://loca
|
||||
| `ENCRYPTION_KEY` | Yes | Key used for encrypting sensitive data (proxies, passwords). | Encryption functionality will not work. |
|
||||
| `MINIO_ENDPOINT` | Yes | Endpoint URL for MinIO, to store Robot Run Screenshots. | Connection to MinIO storage will fail. |
|
||||
| `MINIO_PORT` | Yes | Port number for MinIO service. | Connection to MinIO storage will fail. |
|
||||
| `MINIO_CONSOLE_PORT` | No | Port number for MinIO WebUI service. Needed for Docker setup. | Cannot access MinIO Web UI. |
|
||||
| `MINIO_ACCESS_KEY` | Yes | Access key for authenticating with MinIO. | MinIO authentication will fail. |
|
||||
| `GOOGLE_CLIENT_ID` | No | Client ID for Google OAuth, used for Google Sheet integration authentication. | Google login will not work. |
|
||||
| `GOOGLE_CLIENT_SECRET`| No | Client Secret for Google OAuth. | Google login will not work. |
|
||||
|
||||
@@ -8,7 +8,7 @@ services:
|
||||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||
POSTGRES_DB: ${DB_NAME}
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- "${DB_PORT:-5432}:${DB_PORT:-5432}"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
@@ -23,7 +23,7 @@ services:
|
||||
REDIS_HOST: ${REDIS_HOST}
|
||||
REDIS_PORT: ${REDIS_PORT}
|
||||
ports:
|
||||
- "6379:6379"
|
||||
- "${REDIS_PORT:-6379}:${REDIS_PORT:-6379}"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
|
||||
@@ -32,10 +32,10 @@ services:
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ACCESS_KEY}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_SECRET_KEY}
|
||||
command: server /data --console-address :9001
|
||||
command: server /data --console-address :${MINIO_CONSOLE_PORT:-9001}
|
||||
ports:
|
||||
- "9000:9000" # API port
|
||||
- "9001:9001" # WebUI port
|
||||
- "${MINIO_PORT:-9000}:${MINIO_PORT:-9000}" # API port
|
||||
- "${MINIO_CONSOLE_PORT:-9001}:${MINIO_CONSOLE_PORT:-9001}" # WebUI port
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
|
||||
@@ -45,9 +45,10 @@ services:
|
||||
#dockerfile: server/Dockerfile
|
||||
image: getmaxun/maxun-backend:v0.0.2
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "${BACKEND_PORT:-8080}:${BACKEND_PORT:-8080}"
|
||||
env_file: .env
|
||||
environment:
|
||||
BACKEND_URL: ${BACKEND_URL}
|
||||
# to ensure Playwright works in Docker
|
||||
PLAYWRIGHT_BROWSERS_PATH: /ms-playwright
|
||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 0
|
||||
@@ -56,9 +57,8 @@ services:
|
||||
CHROMIUM_FLAGS: '--disable-gpu --no-sandbox --headless=new'
|
||||
security_opt:
|
||||
- seccomp=unconfined # This might help with browser sandbox issues
|
||||
# Increase shared memory size for Chromium
|
||||
shm_size: '2gb'
|
||||
mem_limit: 2g # Set a 2GB memory limit
|
||||
shm_size: '2gb' # Increase shared memory size for Chromium
|
||||
mem_limit: 2g # Set a 2GB memory limit
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
@@ -74,11 +74,14 @@ services:
|
||||
#dockerfile: Dockerfile
|
||||
image: getmaxun/maxun-frontend:v0.0.1
|
||||
ports:
|
||||
- "5173:5173"
|
||||
- "${FRONTEND_PORT:-5173}:${FRONTEND_PORT:-5173}"
|
||||
env_file: .env
|
||||
environment:
|
||||
PUBLIC_URL: ${PUBLIC_URL}
|
||||
BACKEND_URL: ${BACKEND_URL}
|
||||
volumes:
|
||||
- ./:/app # Mount entire frontend app directory for hot reloading
|
||||
- /app/node_modules # Anonymous volume to prevent overwriting node_modules
|
||||
- /app/node_modules # Anonymous volume to prevent overwriting node_modules
|
||||
depends_on:
|
||||
- backend
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const SERVER_PORT = process.env.SERVER_PORT ? Number(process.env.SERVER_PORT) : 8080
|
||||
export const SERVER_PORT = process.env.BACKEND_PORT ? Number(process.env.BACKEND_PORT) : 8080
|
||||
export const DEBUG = process.env.DEBUG === 'true'
|
||||
export const LOGS_PATH = process.env.LOGS_PATH ?? 'server/logs'
|
||||
export const ANALYTICS_ID = 'oss'
|
||||
@@ -384,7 +384,7 @@ router.get(
|
||||
httpOnly: false,
|
||||
maxAge: 60000,
|
||||
});
|
||||
res.redirect(`http://localhost:5173`);
|
||||
res.redirect(process.env.PUBLIC_URL as string || "http://localhost:5173");
|
||||
} catch (error: any) {
|
||||
res.status(500).json({ message: `Google OAuth error: ${error.message}` });
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import swaggerSpec from './swagger/config';
|
||||
|
||||
const app = express();
|
||||
app.use(cors({
|
||||
origin: 'http://localhost:5173',
|
||||
origin: process.env.PUBLIC_URL ? process.env.PUBLIC_URL : 'http://localhost:5173',
|
||||
credentials: true,
|
||||
}));
|
||||
app.use(express.json());
|
||||
@@ -92,9 +92,10 @@ app.get('/', function (req, res) {
|
||||
|
||||
// Add CORS headers
|
||||
app.use((req, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Origin', process.env.PUBLIC_URL || 'http://localhost:5173');
|
||||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
||||
res.header('Access-Control-Allow-Credentials', 'true');
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
export default defineConfig(() => {
|
||||
const publicUrl = process.env.VITE_PUBLIC_URL || 'http://localhost:5173';
|
||||
|
||||
return {
|
||||
define: {
|
||||
'import.meta.env.VITE_BACKEND_URL': JSON.stringify(process.env.VITE_BACKEND_URL),
|
||||
'import.meta.env.VITE_PUBLIC_URL': JSON.stringify(publicUrl),
|
||||
},
|
||||
server: {
|
||||
host: new URL(publicUrl).hostname,
|
||||
port: parseInt(new URL(publicUrl).port),
|
||||
},
|
||||
build: {
|
||||
outDir: 'build',
|
||||
manifest: true,
|
||||
|
||||
Reference in New Issue
Block a user