Repository navigation
|
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; |
Replies: 7 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}/*). |
|
can you add an example of where is |
|
in general i want to avoid settings |
|
BTW this doesn't work in the |
|
api: server: export default defineServerConfig({ |
|
A small side note for future generations, the |
|
@keepview is there any chance to get the correct value before the |
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}/*).