fix: 修正无法正常读取GraphQL的问题
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m22s
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m22s
- 将GraphQL移至server/assets,在构建后会被写入server中 - 在server端通过storage读取数据
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import { directus } from '~~/server/utils/directus';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { loadAssetAsString } from '~~/server/utils/serverAssets';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = getRouterParam(event, 'id');
|
||||
@ -10,7 +9,13 @@ export default defineEventHandler(async (event) => {
|
||||
statusMessage: 'Solution ID is required',
|
||||
});
|
||||
|
||||
const query = readFileSync(path.resolve('graphql/solution.graphql'), 'utf-8');
|
||||
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, {
|
||||
|
||||
Reference in New Issue
Block a user