Skip to content

Commit 3f22ecb

Browse files
authored
Merge pull request #301 from alphagov/fix_proxy_setting_in_staging
IA-1609: move setting the trust proxy to before middleware init
2 parents e26acbb + c00dd05 commit 3f22ecb

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/backend/app.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class App {
2929
constructor(routes: Routes[]) {
3030
this.app = express()
3131
this.port = config.port
32+
/*
33+
'trust proxy' must be set to 2 when deployed behind GCP load-balancing in order to correctly identify
34+
the requestor's IP address rather than that of the load-balancer. This is required for per-user rate-limiting.
35+
See also - https://cloud.google.com/load-balancing/docs/https#x-forwarded-for_header
36+
*/
37+
this.app.set('trust proxy', 2)
3238

3339
this.initializeMiddlewares()
3440
this.initializeRoutes(routes)
@@ -125,12 +131,6 @@ class App {
125131
genid: generateSessionId,
126132
})
127133
)
128-
/*
129-
'trust proxy' must be set to 2 when deployed behind GCP load-balancing in order to correctly identify
130-
the requestor's IP address rather than that of the load-balancer. This is required for per-user rate-limiting.
131-
See also - https://cloud.google.com/load-balancing/docs/https#x-forwarded-for_header
132-
*/
133-
this.app.set('trust proxy', 2)
134134
this.app.use(passport.initialize())
135135
this.app.use(passport.session())
136136

0 commit comments

Comments
 (0)