Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f476dff

Browse files
add trust proxy
1 parent 7fa9842 commit f476dff

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

‎src/app.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ dotenv.config();
88

99
const app = express();
1010

11+
// Trust proxy settings for proper client IP handling
12+
app.set('trust proxy', true);
13+
1114
// Middleware
1215
app.use(express.json());
1316
app.use(cors({
1417
origin: config.corsOrigin,
1518
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
16-
allowedHeaders: ['Content-Type', 'x-api-key', 'Authorization', 'X-Requested-With'],
19+
allowedHeaders: ['Content-Type', 'x-api-key', 'Authorization', 'X-Requested-With','X-Forwarded-For','X-Real-IP'],
1720
exposedHeaders: ['Content-Length', 'Content-Type'],
1821
credentials: true,
1922
maxAge: 86400,
@@ -22,9 +25,16 @@ app.use(cors({
2225

2326
// Add headers middleware
2427
const headersMiddleware: RequestHandler = (req, res, next) => {
28+
// Get the actual client IP when behind a proxy
29+
const clientIP = req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.ip;
30+
2531
res.header('Access-Control-Allow-Origin', '*');
2632
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
27-
res.header('Access-Control-Allow-Headers', 'Content-Type, x-api-key, Authorization, X-Requested-With');
33+
res.header('Access-Control-Allow-Headers', 'Content-Type, x-api-key, Authorization, X-Requested-With, X-Forwarded-For, X-Real-IP');
34+
35+
// Set Cache-Control to no-cache for streaming responses
36+
res.header('Cache-Control', 'no-cache, no-transform');
37+
2838
if (req.method === 'OPTIONS') {
2939
res.status(204).end();
3040
return;

‎src/services/ollama.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class OllamaService {
3232
res.setHeader('Content-Type', 'text/event-stream');
3333
res.setHeader('Cache-Control', 'no-cache, no-transform');
3434
res.setHeader('Connection', 'keep-alive');
35+
res.setHeader('X-Accel-Buffering', 'no'); // Disable nginx buffering
3536
res.setHeader('Transfer-Encoding', 'chunked');
3637
res.flushHeaders();
3738
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /