Skip to content

Commit 024f674

Browse files
committed
don't import fastify swagger in lambda
1 parent 260d6aa commit 024f674

File tree

1 file changed

+109
-106
lines changed

1 file changed

+109
-106
lines changed

src/api/index.ts

Lines changed: 109 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const now = () => Date.now();
5959
async function init(prettyPrint: boolean = false, initClients: boolean = true) {
6060
const isRunningInLambda =
6161
process.env.LAMBDA_TASK_ROOT || process.env.AWS_LAMBDA_FUNCTION_NAME;
62-
let isSwaggerServer = true;
62+
let isSwaggerServer = false;
6363
const transport = prettyPrint
6464
? {
6565
target: "pino-pretty",
@@ -95,119 +95,122 @@ async function init(prettyPrint: boolean = false, initClients: boolean = true) {
9595
await app.register(evaluatePoliciesPlugin);
9696
await app.register(errorHandlerPlugin);
9797
await app.register(fastifyZodOpenApiPlugin);
98-
try {
99-
const fastifySwagger = import("@fastify/swagger");
100-
const fastifySwaggerUI = import("@fastify/swagger-ui");
101-
await app.register(fastifySwagger, {
102-
openapi: {
103-
info: {
104-
title: "ACM @ UIUC Core API",
105-
description: "ACM @ UIUC Core Management Platform",
106-
version: "1.0.0",
107-
contact: {
108-
name: "ACM @ UIUC Infrastructure Team",
109-
110-
url: "infra.acm.illinois.edu",
111-
},
112-
license: {
113-
name: "BSD 3-Clause",
114-
identifier: "BSD-3-Clause",
115-
url: "https://github.com/acm-uiuc/core/blob/main/LICENSE",
116-
},
117-
termsOfService: "https://core.acm.illinois.edu/tos",
118-
},
119-
servers: [
120-
{
121-
url: "https://core.acm.illinois.edu",
122-
description: "Production API server",
123-
},
124-
{
125-
url: "https://core.aws.qa.acmuiuc.org",
126-
description: "QA API server",
127-
},
128-
],
129-
130-
tags: [
131-
{
132-
name: "Events",
133-
description:
134-
"Retrieve ACM @ UIUC-wide and organization-specific calendars and event metadata.",
135-
},
136-
{
137-
name: "Generic",
138-
description: "Retrieve metadata about a user or ACM @ UIUC .",
139-
},
140-
{
141-
name: "iCalendar Integration",
142-
description:
143-
"Retrieve Events calendars in iCalendar format (for integration with external calendar clients).",
144-
},
145-
{
146-
name: "IAM",
147-
description:
148-
"Identity and Access Management for internal services.",
149-
},
150-
{ name: "Linkry", description: "Link Shortener." },
151-
{
152-
name: "Logging",
153-
description: "View audit logs for various services.",
154-
},
155-
{
156-
name: "Membership",
157-
description: "Purchasing or checking ACM @ UIUC membership.",
158-
},
159-
{
160-
name: "Tickets/Merchandise",
161-
description: "Handling the tickets and merchandise lifecycle.",
162-
},
163-
{
164-
name: "Mobile Wallet",
165-
description: "Issuing Apple/Google Wallet passes.",
166-
},
167-
{
168-
name: "Stripe",
169-
description:
170-
"Collecting payments for ACM @ UIUC invoices and other services.",
171-
},
172-
{
173-
name: "Room Requests",
174-
description:
175-
"Creating room reservation requests for ACM @ UIUC within University buildings.",
176-
},
177-
{
178-
name: "API Keys",
179-
description: "Manage the lifecycle of API keys.",
98+
if (!isRunningInLambda) {
99+
try {
100+
const fastifySwagger = import("@fastify/swagger");
101+
const fastifySwaggerUI = import("@fastify/swagger-ui");
102+
await app.register(fastifySwagger, {
103+
openapi: {
104+
info: {
105+
title: "ACM @ UIUC Core API",
106+
description: "ACM @ UIUC Core Management Platform",
107+
version: "1.0.0",
108+
contact: {
109+
name: "ACM @ UIUC Infrastructure Team",
110+
111+
url: "infra.acm.illinois.edu",
112+
},
113+
license: {
114+
name: "BSD 3-Clause",
115+
identifier: "BSD-3-Clause",
116+
url: "https://github.com/acm-uiuc/core/blob/main/LICENSE",
117+
},
118+
termsOfService: "https://core.acm.illinois.edu/tos",
180119
},
181-
],
120+
servers: [
121+
{
122+
url: "https://core.acm.illinois.edu",
123+
description: "Production API server",
124+
},
125+
{
126+
url: "https://core.aws.qa.acmuiuc.org",
127+
description: "QA API server",
128+
},
129+
],
182130

183-
openapi: "3.1.0" satisfies ZodOpenApiVersion, // If this is not specified, it will default to 3.1.0
184-
components: {
185-
securitySchemes: {
186-
bearerAuth: {
187-
type: "http",
188-
scheme: "bearer",
189-
bearerFormat: "JWT",
131+
tags: [
132+
{
133+
name: "Events",
190134
description:
191-
"Authorization: Bearer {token}\n\nThis API uses JWT tokens issued by Entra ID (Azure AD) with the Core API audience. Tokens must be included in the Authorization header as a Bearer token for all protected endpoints.",
135+
"Retrieve ACM @ UIUC-wide and organization-specific calendars and event metadata.",
192136
},
193-
apiKeyAuth: {
194-
type: "apiKey",
195-
in: "header",
196-
name: "X-Api-Key",
137+
{
138+
name: "Generic",
139+
description: "Retrieve metadata about a user or ACM @ UIUC .",
140+
},
141+
{
142+
name: "iCalendar Integration",
143+
description:
144+
"Retrieve Events calendars in iCalendar format (for integration with external calendar clients).",
145+
},
146+
{
147+
name: "IAM",
148+
description:
149+
"Identity and Access Management for internal services.",
150+
},
151+
{ name: "Linkry", description: "Link Shortener." },
152+
{
153+
name: "Logging",
154+
description: "View audit logs for various services.",
155+
},
156+
{
157+
name: "Membership",
158+
description: "Purchasing or checking ACM @ UIUC membership.",
159+
},
160+
{
161+
name: "Tickets/Merchandise",
162+
description: "Handling the tickets and merchandise lifecycle.",
163+
},
164+
{
165+
name: "Mobile Wallet",
166+
description: "Issuing Apple/Google Wallet passes.",
167+
},
168+
{
169+
name: "Stripe",
170+
description:
171+
"Collecting payments for ACM @ UIUC invoices and other services.",
172+
},
173+
{
174+
name: "Room Requests",
175+
description:
176+
"Creating room reservation requests for ACM @ UIUC within University buildings.",
177+
},
178+
{
179+
name: "API Keys",
180+
description: "Manage the lifecycle of API keys.",
181+
},
182+
],
183+
184+
openapi: "3.1.0" satisfies ZodOpenApiVersion, // If this is not specified, it will default to 3.1.0
185+
components: {
186+
securitySchemes: {
187+
bearerAuth: {
188+
type: "http",
189+
scheme: "bearer",
190+
bearerFormat: "JWT",
191+
description:
192+
"Authorization: Bearer {token}\n\nThis API uses JWT tokens issued by Entra ID (Azure AD) with the Core API audience. Tokens must be included in the Authorization header as a Bearer token for all protected endpoints.",
193+
},
194+
apiKeyAuth: {
195+
type: "apiKey",
196+
in: "header",
197+
name: "X-Api-Key",
198+
},
197199
},
198200
},
199201
},
200-
},
201-
transform: fastifyZodOpenApiTransform,
202-
transformObject: fastifyZodOpenApiTransformObject,
203-
});
204-
await app.register(fastifySwaggerUI, {
205-
routePrefix: "/api/documentation",
206-
});
207-
} catch (e) {
208-
app.log.warn("Fastify Swagger not created!");
209-
isSwaggerServer = false;
202+
transform: fastifyZodOpenApiTransform,
203+
transformObject: fastifyZodOpenApiTransformObject,
204+
});
205+
await app.register(fastifySwaggerUI, {
206+
routePrefix: "/api/documentation",
207+
});
208+
isSwaggerServer = true;
209+
} catch (e) {
210+
app.log.warn("Fastify Swagger not created!");
211+
}
210212
}
213+
211214
await app.register(fastifyStatic, {
212215
root: path.join(__dirname, "public"),
213216
prefix: "/",

0 commit comments

Comments
 (0)