Add a /health function for ease of benchmarking (#412)
* Slightly more defensive API endpoints * Add health endpoint for benchmarking trivial Firebase fns
This commit is contained in:
parent
00f142ec7e
commit
7572e07489
|
@ -137,11 +137,11 @@ export const validate = <T extends z.ZodTypeAny>(schema: T, val: unknown) => {
|
||||||
|
|
||||||
export const newEndpoint = (methods: [string], fn: Handler) =>
|
export const newEndpoint = (methods: [string], fn: Handler) =>
|
||||||
functions.runWith({ minInstances: 1 }).https.onRequest(async (req, res) => {
|
functions.runWith({ minInstances: 1 }).https.onRequest(async (req, res) => {
|
||||||
await applyCors(req, res, {
|
|
||||||
origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST],
|
|
||||||
methods: methods,
|
|
||||||
})
|
|
||||||
try {
|
try {
|
||||||
|
await applyCors(req, res, {
|
||||||
|
origin: [CORS_ORIGIN_MANIFOLD, CORS_ORIGIN_LOCALHOST],
|
||||||
|
methods: methods,
|
||||||
|
})
|
||||||
if (!methods.includes(req.method)) {
|
if (!methods.includes(req.method)) {
|
||||||
const allowed = methods.join(', ')
|
const allowed = methods.join(', ')
|
||||||
throw new APIError(405, `This endpoint supports only ${allowed}.`)
|
throw new APIError(405, `This endpoint supports only ${allowed}.`)
|
||||||
|
|
11
functions/src/health.ts
Normal file
11
functions/src/health.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { newEndpoint } from './api'
|
||||||
|
|
||||||
|
export const health = newEndpoint(['GET'], async (_req, [user, _]) => {
|
||||||
|
return {
|
||||||
|
message: 'Server is working.',
|
||||||
|
user: {
|
||||||
|
id: user.id,
|
||||||
|
username: user.username,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
|
@ -3,6 +3,7 @@ import * as admin from 'firebase-admin'
|
||||||
admin.initializeApp()
|
admin.initializeApp()
|
||||||
|
|
||||||
// export * from './keep-awake'
|
// export * from './keep-awake'
|
||||||
|
export * from './health'
|
||||||
export * from './transact'
|
export * from './transact'
|
||||||
export * from './place-bet'
|
export * from './place-bet'
|
||||||
export * from './resolve-market'
|
export * from './resolve-market'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user