-
|
Hi, I have a I tried to check current example code: import type { MiddlewareObj } from '@modern-js/server-runtime';
import { getHandlerError } from '@server/context';
import { runFuncWithMeasure } from '@/server/performanceMeasureService';
const measureMiddleware: MiddlewareObj = {
name: 'measure-middleware',
handler: async (c, next) => {
const measureKey = c.req.path; // this returns `/api/user/exampleUserId` and i want `/api/user/:userId`
try {
await runFuncWithMeasure(
async () => {
await next();
const error = getHandlerError(c);
if (error) {
throw error;
}
},
{
measureKey,
}
);
} catch (_avoid_double_error) {}
},
};
export default measureMiddleware; |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
|
The middleware of the custom server is global, so it's expected that you get You should define the middleware for bff api to get the routePath you expect. If you need to get the routePath of bff api in the custom server, you can use c.set('routePath', c.req.routePath) in the lambda function, and then get it through c.get('routePath') in the custom server (please note that this method only supports the production environment. Due to the need to support hot updates for bff in the development environment, the routePath in the lambda function is fixed as ${prefix}/*). |
Beta Was this translation helpful? Give feedback.
-
|
can you add an example of where is |
Beta Was this translation helpful? Give feedback.
-
|
in general i want to avoid settings |
Beta Was this translation helpful? Give feedback.
-
|
BTW this doesn't work in the |
Beta Was this translation helpful? Give feedback.
-
|
api: server: export default defineServerConfig({ |
Beta Was this translation helpful? Give feedback.
The middleware of the custom server is global, so it's expected that you get
/*when accessing c.req.routePath.You should define the middleware for bff api to get the routePath you expect.
If you need to get the routePath of bff api in the custom server, you can use c.set('routePath', c.req.routePath) in the lambda function, and then get it through c.get('routePath') in the custom server (please note that this method only supports the production environment. Due to the need to support hot updates for bff in the development environment, the routePath in the lambda function is fixed as ${prefix}/*).