Skip to content

Commit

Permalink
refactor(cu): reconsolidate ao http side effect routes and middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Feb 6, 2025
1 parent 5708781 commit 4fcbae6
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion servers/cu/src/effects/ao-http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import FastifyMiddie from '@fastify/middie'
import cors from 'cors'
import helmet from 'helmet'

import { withMetricRoutes } from '../routes/metrics.js'
import { withMetricRoutes } from './routes/metrics.js'
import { withStateRoutes } from './routes/state.js'
import { withResultRoutes } from './routes/result.js'
import { withDryRunRoutes } from './routes/dryRun.js'
Expand Down
6 changes: 3 additions & 3 deletions servers/cu/src/effects/ao-http/routes/cron.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { always, compose, identity } from 'ramda'
import { z } from 'zod'

import { withErrorHandler } from '../../middleware/withErrorHandler.js'
import { withErrorHandler } from './middleware/withErrorHandler.js'
import { withCuMode } from './middleware/withCuMode.js'
import { withMetrics } from '../../middleware/withMetrics.js'
import { withProcessRestrictionFromPath } from '../../middleware/withProcessRestriction.js'
import { withMetrics } from './middleware/withMetrics.js'
import { withProcessRestrictionFromPath } from './middleware/withProcessRestriction.js'

/**
* TODO: could be moved into a route utils or middleware
Expand Down
6 changes: 3 additions & 3 deletions servers/cu/src/effects/ao-http/routes/dryRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { z } from 'zod'

import { busyIn } from '../../../domain/utils.js'

import { withErrorHandler } from '../../middleware/withErrorHandler.js'
import { withMetrics } from '../../middleware/withMetrics.js'
import { withProcessRestrictionFromQuery } from '../../middleware/withProcessRestriction.js'
import { withErrorHandler } from './middleware/withErrorHandler.js'
import { withMetrics } from './middleware/withMetrics.js'
import { withProcessRestrictionFromQuery } from './middleware/withProcessRestriction.js'

const inputSchema = z.object({
processId: z.string().min(1, 'a process-id query parameter is required'),
Expand Down
2 changes: 1 addition & 1 deletion servers/cu/src/effects/ao-http/routes/healthcheck.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { always, compose } from 'ramda'

import { withErrorHandler } from '../../middleware/withErrorHandler.js'
import { withErrorHandler } from './middleware/withErrorHandler.js'

export const withHealthcheckRoutes = (app) => {
// healthcheck
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { always, compose } from 'ramda'

import { withErrorHandler } from '../middleware/withErrorHandler.js'
import { withErrorHandler } from './middleware/withErrorHandler.js'

export const withMetricRoutes = (app) => {
app.get(
Expand All @@ -13,7 +13,7 @@ export const withMetricRoutes = (app) => {
domain: { apis: { metrics } }
} = req

if (!config.ENABLE_METRICS_ENDPOINT) return res.status(404)
if (!config.ENABLE_METRICS_ENDPOINT) return res.status(404).send('Not Found')

await metrics.compute()
.toPromise()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { errFrom } from '../../domain/utils.js'
import { errFrom } from '../../../../domain/utils.js'

/**
* A middleware that simply calls the next handler in the chain.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { always } from 'ramda'

import { histogramWith, summaryWith } from '../metrics.js'
import { histogramWith, summaryWith } from '../../../metrics.js'

const histogram = histogramWith()({
name: 'http_request_duration_seconds',
Expand Down
6 changes: 3 additions & 3 deletions servers/cu/src/effects/ao-http/routes/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { z } from 'zod'
import { busyIn } from '../../../domain/utils.js'

import { withInMemoryCache } from './middleware/withInMemoryCache.js'
import { withErrorHandler } from '../../middleware/withErrorHandler.js'
import { withErrorHandler } from './middleware/withErrorHandler.js'
import { withCuMode } from './middleware/withCuMode.js'
import { withMetrics } from '../../middleware/withMetrics.js'
import { withProcessRestrictionFromQuery } from '../../middleware/withProcessRestriction.js'
import { withMetrics } from './middleware/withMetrics.js'
import { withProcessRestrictionFromQuery } from './middleware/withProcessRestriction.js'

const inputSchema = z.object({
messageUid: z.string().min(1, 'a message unique identifier is required'),
Expand Down
6 changes: 3 additions & 3 deletions servers/cu/src/effects/ao-http/routes/results.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { always, compose, identity } from 'ramda'
import { z } from 'zod'

import { withErrorHandler } from '../../middleware/withErrorHandler.js'
import { withErrorHandler } from './middleware/withErrorHandler.js'
import { withCuMode } from './middleware/withCuMode.js'
import { withProcessRestrictionFromPath } from '../../middleware/withProcessRestriction.js'
import { withMetrics } from '../../middleware/withMetrics.js'
import { withProcessRestrictionFromPath } from './middleware/withProcessRestriction.js'
import { withMetrics } from './middleware/withMetrics.js'

/**
* TODO: could be moved into a route utils or middleware
Expand Down
6 changes: 3 additions & 3 deletions servers/cu/src/effects/ao-http/routes/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { z } from 'zod'

import { arrayBufferFromMaybeView, busyIn } from '../../../domain/utils.js'

import { withErrorHandler } from '../../middleware/withErrorHandler.js'
import { withErrorHandler } from './middleware/withErrorHandler.js'
import { withCuMode } from './middleware/withCuMode.js'
import { withProcessRestrictionFromPath } from '../../middleware/withProcessRestriction.js'
import { withMetrics } from '../../middleware/withMetrics.js'
import { withProcessRestrictionFromPath } from './middleware/withProcessRestriction.js'
import { withMetrics } from './middleware/withMetrics.js'

const inputSchema = z.object({
processId: z.string().min(1, 'an ao process id is required'),
Expand Down

0 comments on commit 4fcbae6

Please sign in to comment.