Skip to content

Commit e2536e5

Browse files
smashingtagsclaude
andcommitted
fix: nginx API proxy rewrite + ESM require() errors
- nginx.conf: add rewrite ^/api/(.*) /$1 to strip /api/ prefix before proxying to backend (backend routes are /applications not /api/applications) - auth.js: replace require('crypto') with ESM import (fixes crash in ES module) - index.js: import spawn from child_process at top level, remove inline require() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 914f920 commit e2536e5

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

nginx.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ server {
3636
}
3737

3838
# API proxy to backend container
39-
# Use variable so nginx starts even if backend isn't ready yet
40-
location /api {
39+
# Strips /api/ prefix — backend routes are /applications, /auth/login, etc.
40+
location /api/ {
4141
resolver 127.0.0.11 valid=10s ipv6=off;
4242
set $backend http://homelabarr-backend:8092;
43+
rewrite ^/api/(.*) /$1 break;
4344
proxy_pass $backend;
4445
proxy_http_version 1.1;
4546
proxy_set_header Upgrade $http_upgrade;

server/auth.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import jwt from 'jsonwebtoken';
22
import bcrypt from 'bcryptjs';
3+
import crypto from 'crypto';
34
import fs from 'fs';
45
import path from 'path';
56

67
// Configuration
7-
const JWT_SECRET = process.env.JWT_SECRET || require('crypto').randomBytes(32).toString('hex');
8+
const JWT_SECRET = process.env.JWT_SECRET || crypto.randomBytes(32).toString('hex');
89
const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || '24h';
910
const USERS_FILE = path.join(process.cwd(), 'server', 'config', 'users.json');
1011

server/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'path';
77
import helmet from 'helmet';
88
import os from 'os';
99
import { chmodSync } from 'fs';
10-
import { execSync } from 'child_process';
10+
import { execSync, spawn } from 'child_process';
1111
import { promisify } from 'util';
1212
import {
1313
initializeAuth,
@@ -3518,7 +3518,7 @@ app.post('/deploy', authEnabled ? requireAuth : optionalAuth, async (req, res) =
35183518
logger.info('🐳 Using direct Docker CLI deployment for it-tools MVP');
35193519

35203520
try {
3521-
const { spawn } = require('child_process');
3521+
// spawn imported at top of file via ESM import
35223522

35233523
const containerName = `homelabarr-${appId}-${Date.now()}`;
35243524
const port = config.port || '8080';
@@ -3622,7 +3622,7 @@ app.post('/deploy', authEnabled ? requireAuth : optionalAuth, async (req, res) =
36223622

36233623
// For MVP, create a simple container deployment using docker CLI
36243624
try {
3625-
const { spawn } = require('child_process');
3625+
// spawn imported at top of file via ESM import
36263626

36273627
// Basic it-tools container deployment
36283628
if (appId === 'it-tools') {

0 commit comments

Comments
 (0)