22 lines
565 B
TypeScript
22 lines
565 B
TypeScript
import { productService } from '~~/server/services/cms/productService';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const id = getRouterParam(event, 'id');
|
|
if (!id)
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: 'Product ID is required',
|
|
});
|
|
const locale = getHeader(event, 'x-locale') || 'zh-CN';
|
|
|
|
const product = await productService.getProductById(id, locale);
|
|
|
|
product.description = rewriteAssetUrls(
|
|
product.description,
|
|
useRuntimeConfig().public.directus.url,
|
|
'/api/assets'
|
|
);
|
|
|
|
return product;
|
|
});
|