All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m22s
- 将GraphQL移至server/assets,在构建后会被写入server中 - 在server端通过storage读取数据
22 lines
596 B
TypeScript
22 lines
596 B
TypeScript
import { directus } from '~~/server/utils/directus';
|
|
import { loadAssetAsString } from '~~/server/utils/serverAssets';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const query = await loadAssetAsString(
|
|
'assets:server',
|
|
'graphql/solutionList.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: Solution[] }>(query, {
|
|
locale: locale,
|
|
});
|
|
|
|
const solutions = data?.solutions || [];
|
|
|
|
return solutions;
|
|
});
|