All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m22s
- 将GraphQL移至server/assets,在构建后会被写入server中 - 在server端通过storage读取数据
25 lines
629 B
TypeScript
25 lines
629 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/documentList.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<{ product_documents: ProductDocument[] }>(
|
|
query,
|
|
{
|
|
locale: locale,
|
|
}
|
|
);
|
|
|
|
const documents = data?.product_documents;
|
|
|
|
return documents;
|
|
});
|