initial commit. gotta go
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { env } from "~/env";
|
||||
import { db } from "~/server/db";
|
||||
import { logger } from "~/server/logger/log";
|
||||
import { parseSesHook, SesHookParser } from "~/server/service/ses-hook-parser";
|
||||
import { SesSettingsService } from "~/server/service/ses-settings-service";
|
||||
import { SnsNotificationMessage } from "~/types/aws-types";
|
||||
import { env } from '~/env';
|
||||
import { db } from '~/server/db';
|
||||
import { logger } from '~/server/logger/log';
|
||||
import { parseSesHook, SesHookParser } from '~/server/service/ses-hook-parser';
|
||||
import { SesSettingsService } from '~/server/service/ses-settings-service';
|
||||
import { SnsNotificationMessage } from '~/types/aws-types';
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET() {
|
||||
return Response.json({ data: "Hello" });
|
||||
return Response.json({ data: 'Hello' });
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
@@ -18,32 +18,32 @@ export async function POST(req: Request) {
|
||||
|
||||
const isEventValid = await checkEventValidity(data);
|
||||
|
||||
console.log("Is event valid: ", isEventValid);
|
||||
console.log('Is event valid: ', isEventValid);
|
||||
|
||||
if (!isEventValid) {
|
||||
return Response.json({ data: "Event is not valid" });
|
||||
return Response.json({ data: 'Event is not valid' });
|
||||
}
|
||||
|
||||
if (data.Type === "SubscriptionConfirmation") {
|
||||
if (data.Type === 'SubscriptionConfirmation') {
|
||||
return handleSubscription(data);
|
||||
}
|
||||
|
||||
let message = null;
|
||||
|
||||
try {
|
||||
message = JSON.parse(data.Message || "{}");
|
||||
message = JSON.parse(data.Message || '{}');
|
||||
const status = await SesHookParser.queue({
|
||||
event: message,
|
||||
messageId: data.MessageId,
|
||||
});
|
||||
if (!status) {
|
||||
return Response.json({ data: "Error in parsing hook" });
|
||||
return Response.json({ data: 'Error in parsing hook' });
|
||||
}
|
||||
|
||||
return Response.json({ data: "Success" });
|
||||
return Response.json({ data: 'Success' });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return Response.json({ data: "Error is parsing hook" });
|
||||
return Response.json({ data: 'Error is parsing hook' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function POST(req: Request) {
|
||||
*/
|
||||
async function handleSubscription(message: any) {
|
||||
await fetch(message.SubscribeURL, {
|
||||
method: "GET",
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
const topicArn = message.TopicArn as string;
|
||||
@@ -63,7 +63,7 @@ async function handleSubscription(message: any) {
|
||||
});
|
||||
|
||||
if (!setting) {
|
||||
return Response.json({ data: "Setting not found" });
|
||||
return Response.json({ data: 'Setting not found' });
|
||||
}
|
||||
|
||||
await db.sesSetting.update({
|
||||
@@ -77,14 +77,14 @@ async function handleSubscription(message: any) {
|
||||
|
||||
SesSettingsService.invalidateCache();
|
||||
|
||||
return Response.json({ data: "Success" });
|
||||
return Response.json({ data: 'Success' });
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple check to ensure that the event is from the correct topic
|
||||
*/
|
||||
async function checkEventValidity(message: SnsNotificationMessage) {
|
||||
if (env.NODE_ENV === "development") {
|
||||
if (env.NODE_ENV === 'development') {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user