mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 17:46:28 +08:00
framework: prepare for ui-next data fetching logics
This commit is contained in:
1 file changed
+11
-1
@@ -76,7 +76,8 @@ export default (logger, xff, xhost) => async (ctx: KoaContext, next: Next) => {
|
|||||||
response.type = 'application/json';
|
response.type = 'application/json';
|
||||||
} else if (
|
} else if (
|
||||||
request.json || response.redirect
|
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
|
// Send raw data
|
||||||
try {
|
try {
|
||||||
if (typeof response.body === 'object' && request.headers['x-hydro-inject']) {
|
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('uicontext')) response.body.UiContext = UiContext;
|
||||||
if (inject.includes('usercontext')) response.body.UserContext = user;
|
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));
|
response.body = JSON.stringify(response.body, serializer(false, handler));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
response.body = new SystemError('Serialize failure', e.message);
|
response.body = new SystemError('Serialize failure', e.message);
|
||||||
|
|||||||
Reference in new issue
Block a user