framework: prepare for ui-next data fetching logics

This commit is contained in:
Baoshuo committed 2026-05-10 01:12:47 +08:00
1 parent b5ec79d5d6
commit b44135681c
1 file changed
+11 -1
+11 -1
View File
@@ -76,7 +76,8 @@ export default (logger, xff, xhost) => async (ctx: KoaContext, next: Next) => {
response.type = 'application/json';
} else if (
request.json || response.redirect
|| request.query.noTemplate || !response.template) {
|| request.query.noTemplate || !response.template // no template, send raw data
|| request.query._ui_next) { // for ui-next, we always send json
// Send raw data
try {
if (typeof response.body === 'object' && request.headers['x-hydro-inject']) {
@@ -84,6 +85,15 @@ export default (logger, xff, xhost) => async (ctx: KoaContext, next: Next) => {
if (inject.includes('uicontext')) response.body.UiContext = UiContext;
if (inject.includes('usercontext')) response.body.UserContext = user;
}
if (request.query._ui_next) {
response.body = {
// `_matchedRouteName` is koa-router's internal property, but it works,
// maybe we should migrate to a more official solution in the future.
name: ctx._matchedRouteName,
args: response.body || {},
url: ctx.req.url,
};
}
response.body = JSON.stringify(response.body, serializer(false, handler));
} catch (e) {
response.body = new SystemError('Serialize failure', e.message);