feat : notify new update income
This commit is contained in:
+19
-7
@@ -3,7 +3,11 @@ import { limitRequest, trustedClientAddress } from "@/lib/security/rate-limit";
|
||||
import { connection } from "next/server";
|
||||
|
||||
import { normalizeDeploymentId } from "@/lib/deployment/version";
|
||||
import { createEventStream, eventStreamHeaders } from "@/lib/events/sse";
|
||||
import {
|
||||
DEPLOYMENT_EVENT_TOPIC,
|
||||
getLatestDeploymentStatus,
|
||||
} from "@/lib/deployment/repository";
|
||||
import { createRedisNamedEventResponse } from "@/lib/events/redis-stream";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
await connection();
|
||||
@@ -11,12 +15,20 @@ export async function GET(request: Request) {
|
||||
await limitRequest("stream-open", trustedClientAddress(request.headers), 60);
|
||||
const deploymentId =
|
||||
normalizeDeploymentId(process.env.NEXT_DEPLOYMENT_ID) ?? "development";
|
||||
const channel = createEventStream({ signal: request.signal });
|
||||
channel.sendNamed("deployment", deploymentId);
|
||||
|
||||
return new Response(channel.stream, {
|
||||
headers: eventStreamHeaders(),
|
||||
});
|
||||
return await createRedisNamedEventResponse(
|
||||
DEPLOYMENT_EVENT_TOPIC,
|
||||
"deployment-status",
|
||||
request.signal,
|
||||
async () => {
|
||||
const latestStatus = await getLatestDeploymentStatus();
|
||||
return [
|
||||
{ eventName: "deployment", data: deploymentId },
|
||||
...(latestStatus
|
||||
? [{ eventName: "deployment-status", data: JSON.stringify(latestStatus) }]
|
||||
: []),
|
||||
];
|
||||
},
|
||||
);
|
||||
} catch (cause) {
|
||||
return errorResponse(cause);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user