Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish to prod #901

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
10 changes: 0 additions & 10 deletions apps/api/gql/resolver-context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { Request } 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()];
Expand All @@ -21,11 +16,6 @@ export async function resolverContext(req: Request) {
const adminApiKey = getHeader(req, 'AdminApiKey');
const chainId = getHeader(req, 'ChainId');

if (chainId && networkContext.isValidChainId(chainId)) {
initRequestScopedContext();
setRequestScopedContextValue('chainId', chainId);
}

// Initialize context if it doesn't exist
return {
accountAddress: accountAddress ? accountAddress.toLowerCase() : null,
Expand Down
1 change: 1 addition & 0 deletions apps/api/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './corsMiddleware';
export * from './lowerCaseMiddleware';
export * from './sessionMiddleware';
24 changes: 24 additions & 0 deletions apps/api/middleware/sessionMiddleware.ts
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();
}
}
3 changes: 2 additions & 1 deletion apps/api/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import helmet from 'helmet';
import * as http from 'http';
import { env } from '../env';
import { loadRestRoutes } from './rest-routes';
import { corsMiddleware, lowerCaseMiddleware } from './middleware';
import { corsMiddleware, lowerCaseMiddleware, sessionMiddleware } from './middleware';
import {
ApolloServerPluginDrainHttpServer,
ApolloServerPluginLandingPageGraphQLPlayground,
Expand Down Expand Up @@ -34,6 +34,7 @@ const configureHelmet = (app: express.Express) => {

const configureMiddlewares = (app: express.Express) => {
app.use(corsMiddleware);
app.use(sessionMiddleware);
app.use(lowerCaseMiddleware);
};

Expand Down
Loading