blob: d8a3008e2f33aba9d7fcb10a021f7a2e2b041c44 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import { perform } from "./email";
import type { EmailJob } from "./job";
import { ConsoleLogger } from "./logger";
export const main = (port: number) => {
const server = Bun.serve({
port,
async fetch(req) {
ConsoleLogger.log(`Received request: ${req.url}`)();
const url = new URL(req.url);
if (req.method === "POST" && url.pathname === "/api/email") {
const job: EmailJob = await req.json();
const jobInsensitive = structuredClone(job);
jobInsensitive.from.username = "****REDACTED****";
jobInsensitive.from.password = "****REDACTED****";
jobInsensitive.to.username = "****REDACTED****";
jobInsensitive.to.password = "****REDACTED****";
ConsoleLogger.log(
`Received email job: ${JSON.stringify(jobInsensitive)}`,
)();
const performEmailTest = perform(job)();
return await performEmailTest
.then(() => {
return Response.json({ success: true });
})
.catch((error) => {
return new Response(error.message, {
status: 400,
});
});
}
return new Response("404!", { status: 404 });
},
});
ConsoleLogger.log(`Listening on port ${port}`)();
return server;
};
|