Skip to content

Commit

Permalink
removed parameter in setupRoutes (#805)
Browse files Browse the repository at this point in the history
line 77 had a reference to `server` directly whereas the other routes
used the `srv` param. this pr attempts to simplify and standardize
  • Loading branch information
mechanical-turk authored Aug 16, 2024
1 parent b775c20 commit 149b442
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/stream-metadata/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ dotenv.config({
})

const IntStringSchema = z.string().regex(/^[0-9]+$/)
const BoolStringSchema = z.string().regex(/^(true|false)$/)

const NumberFromIntStringSchema = IntStringSchema.transform((str) => parseInt(str, 10))
const BoolFromStringSchema = BoolStringSchema.transform((str) => str === 'true')

const envSchema = z.object({
RIVER_ENV: z.string(),
RIVER_CHAIN_RPC_URL: z.string().url(),
PORT: NumberFromIntStringSchema,
LOG_LEVEL: z.string().optional().default('info'),
LOG_PRETTY: z.boolean().optional().default(true),
LOG_PRETTY: BoolFromStringSchema.optional().default('true'),
})

function makeConfig() {
Expand Down
10 changes: 5 additions & 5 deletions packages/stream-metadata/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ async function registerPlugins() {
logger.info('CORS registered successfully')
}

export function setupRoutes(srv: Server) {
function setupRoutes() {
/*
* Routes
*/
srv.get('/health', async (request, reply) => {
server.get('/health', async (request, reply) => {
logger.info(`GET /health`)
return checkHealth(request, reply)
})

srv.get('/space/:spaceAddress', async (request, reply) => {
server.get('/space/:spaceAddress', async (request, reply) => {
const { spaceAddress } = request.params as { spaceAddress?: string }
logger.info({ spaceAddress }, 'GET /space/../metadata')

const { protocol, serverAddress } = getServerInfo()
return fetchSpaceMetadata(request, reply, `${protocol}://${serverAddress}`)
})

srv.get('/space/:spaceAddress/image', async (request, reply) => {
server.get('/space/:spaceAddress/image', async (request, reply) => {
const { spaceAddress } = request.params as { spaceAddress?: string }
logger.info({ spaceAddress }, 'GET /space/../image')

Expand Down Expand Up @@ -106,7 +106,7 @@ process.on('SIGTERM', async () => {
async function main() {
try {
await registerPlugins()
setupRoutes(server)
setupRoutes()
await server.listen({ port: config.port })
logger.info('Server started')
} catch (error) {
Expand Down

0 comments on commit 149b442

Please sign in to comment.