-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #901 from balancer/v3-canary
publish to prod
- Loading branch information
Showing
4 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './corsMiddleware'; | ||
export * from './lowerCaseMiddleware'; | ||
export * from './sessionMiddleware'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NextFunction, Request, Response } from 'express'; | ||
import { networkContext } from '../../../modules/network/network-context.service'; | ||
import { | ||
initRequestScopedContext, | ||
setRequestScopedContextValue, | ||
} from '../../../modules/context/request-scoped-context'; | ||
|
||
function getHeader(req: Request, key: string): string | undefined { | ||
const value = req.headers[key.toLowerCase()]; | ||
return Array.isArray(value) ? value[0] : value; | ||
} | ||
|
||
export async function sessionMiddleware(req: Request, res: Response, next: NextFunction) { | ||
const chainId = getHeader(req, 'ChainId'); | ||
|
||
if (chainId && networkContext.isValidChainId(chainId)) { | ||
initRequestScopedContext(); | ||
setRequestScopedContextValue('chainId', chainId); | ||
|
||
next(); | ||
} else { | ||
next(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters