All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m22s
- 将GraphQL移至server/assets,在构建后会被写入server中 - 在server端通过storage读取数据
34 lines
902 B
TypeScript
34 lines
902 B
TypeScript
import { directus } from '~~/server/utils/directus';
|
|
import { loadAssetAsString } from '~~/server/utils/serverAssets';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const id = getRouterParam(event, 'id');
|
|
if (!id)
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: 'Solution ID is required',
|
|
});
|
|
|
|
const query = await loadAssetAsString(
|
|
'assets:server',
|
|
'graphql/solution.graphql'
|
|
);
|
|
if (!query)
|
|
throw createError({ statusCode: 500, message: 'GraphQL query not found' });
|
|
|
|
const locale = getHeader(event, 'x-locale') || 'zh-CN';
|
|
|
|
const data = await directus.query<{ solutions_by_id: Solution }>(query, {
|
|
id: id,
|
|
locale: locale,
|
|
});
|
|
|
|
const solution = data?.solutions_by_id;
|
|
|
|
if (!solution || solution.status === 'archived') {
|
|
throw createError({ statusCode: 404, statusMessage: 'Solution not found' });
|
|
}
|
|
|
|
return solution;
|
|
});
|