Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/backend/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { requirePermissions } from '@wxyc/authentication';
const port = process.env.PORT || 8080;
const app = express();

app.set('trust proxy', true);

//Interpret parse json into js objects
app.use(express.json());

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/config/trust-proxy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';

describe('Express trust proxy configuration', () => {
const appSource = readFileSync(resolve(__dirname, '../../../apps/backend/app.ts'), 'utf-8');

it('should enable trust proxy so req.ip reflects the real client IP behind a reverse proxy', () => {
expect(appSource).toMatch(/app\.set\(\s*['"]trust proxy['"]/);
});
});
Loading