Skip to content
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
8 changes: 8 additions & 0 deletions server/src/resources/base-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ function validateIncludes(query: object, allowedIncludes: string[]) {
}
}

function setHeaders(res: Response, headers?: Record<string, string>) {
if (headers) {
res.header(headers)
}
}

function bindEndpoint<E extends Endpoint, ListFilter>(
router: Router,
endpoint: E,
Expand Down Expand Up @@ -103,6 +109,8 @@ function bindEndpoint<E extends Endpoint, ListFilter>(
) as EndpointTypes<E>['request']['query']['output']
validateIncludes(query, endpoint.allowedIncludes as string[])

setHeaders(res, endpoint.responseHeaders)

const isFile = req.headers['content-type']?.toLowerCase() === 'application/octet-stream'
if (isFile) {
const chunks: ArrayBuffer[] = []
Expand Down
2 changes: 2 additions & 0 deletions shared/src/data-transfer/resources/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function createRESTEndpoints<
body: EmptyObjectSchema,
},
responseSchema: schema,
responseHeaders: { 'Cache-Control': 'no-cache' },
}
}

Expand Down Expand Up @@ -134,6 +135,7 @@ export function createRESTEndpoints<
body: EmptyObjectSchema,
},
responseSchema: listResponse(schema),
responseHeaders: { 'Cache-Control': 'no-cache' },
}
}

Expand Down
1 change: 1 addition & 0 deletions shared/src/data-transfer/resources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface Endpoint<
body: ZodSchemaForIO<Body>
}
responseSchema: ZodSchemaForIO<Response>
responseHeaders?: Record<string, string>
}

export type EndpointsMask = `${'c' | ''}${'r' | ''}${'u' | ''}${'d' | ''}${'l' | ''}`
Expand Down