Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1a4a84d24 | ||
|
|
a9c57d4985 |
@@ -0,0 +1,44 @@
|
||||
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
|
||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
|
||||
|
||||
export default async function revalidateStorefrontHandler({
|
||||
container,
|
||||
}: SubscriberArgs) {
|
||||
const logger = container.resolve(ContainerRegistrationKeys.LOGGER);
|
||||
|
||||
const storefrontUrl = process.env.STOREFRONT_URL;
|
||||
const secret = process.env.REVALIDATE_SECRET;
|
||||
|
||||
if (!storefrontUrl || !secret) {
|
||||
logger.warn(
|
||||
"STOREFRONT_URL o REVALIDATE_SECRET no configurados; se omite la revalidación del storefront.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${storefrontUrl}/api/revalidate`, {
|
||||
method: "POST",
|
||||
headers: { "x-revalidate-secret": secret },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
logger.warn(
|
||||
`Revalidación del storefront respondió HTTP ${response.status}.`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
`No se pudo revalidar el storefront: ${(error as Error).message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const config: SubscriberConfig = {
|
||||
event: [
|
||||
"product.updated",
|
||||
"product-variant.updated",
|
||||
"product-variant.created",
|
||||
"product-variant.deleted",
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { revalidateTag } from "next/cache";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const secret = request.headers.get("x-revalidate-secret");
|
||||
|
||||
if (!secret || secret !== process.env.REVALIDATE_SECRET) {
|
||||
return Response.json({ message: "Invalid secret" }, { status: 401 });
|
||||
}
|
||||
|
||||
revalidateTag("medusa-products");
|
||||
|
||||
return Response.json({ revalidated: true, tag: "medusa-products" }, { status: 200 });
|
||||
}
|
||||
@@ -22,6 +22,11 @@ stringData:
|
||||
|
||||
JWT_SECRET: CAMBIAR
|
||||
COOKIE_SECRET: CAMBIAR
|
||||
|
||||
# Debe ser el MISMO valor que REVALIDATE_SECRET en el Secret
|
||||
# commerce-storefront: el subscriber de Medusa lo envía como header
|
||||
# x-revalidate-secret al invocar POST /api/revalidate en el storefront.
|
||||
REVALIDATE_SECRET: CAMBIAR
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
@@ -30,3 +35,6 @@ metadata:
|
||||
type: Opaque
|
||||
stringData:
|
||||
MEDUSA_PUBLISHABLE_KEY: pk_CAMBIAR_DESPUES_DE_CREARLA_EN_MEDUSA
|
||||
|
||||
# Mismo valor que REVALIDATE_SECRET en commerce-secrets.
|
||||
REVALIDATE_SECRET: CAMBIAR
|
||||
|
||||
@@ -16,7 +16,7 @@ spec:
|
||||
- name: gitea-registry-secret
|
||||
containers:
|
||||
- name: web
|
||||
image: gitea.cruzcloud.net/devops/ecommerce-frontend:v1.0.87
|
||||
image: gitea.cruzcloud.net/devops/ecommerce-frontend:v1.0.89
|
||||
ports:
|
||||
- containerPort: 80
|
||||
env:
|
||||
|
||||
Reference in New Issue
Block a user