Skip to content

Commit

Permalink
Merge pull request #108 from thanhdanh27600:staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
thanhdanh27600 authored Aug 16, 2023
2 parents 1a9b515 + 3e5ea81 commit 09312bb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
11 changes: 2 additions & 9 deletions controllers/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@ import { api } from 'utils/axios';
import date from 'utils/date';
import HttpStatusCode from 'utils/statusCode';

const TEMPLATE = {
OK: `Machine is working as expected, ${date().toString()}`,
FAIL: `Error! Machine is down!, ${date().toString()}`,
} as const;

export const handler: NextApiHandler<any> = api(async (req, res) => {
if (req.method !== 'POST') {
return res.status(HttpStatusCode.METHOD_NOT_ALLOWED).json({ errorMessage: 'Method Not Allowed' });
}
const body = req.body;
const t = body.t as keyof typeof TEMPLATE;
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com', // e.g., Gmail, Outlook
port: 587,
Expand Down Expand Up @@ -49,7 +42,7 @@ export const handler: NextApiHandler<any> = api(async (req, res) => {
sender: 'Dolph Notify',
to: 'dolph.pham@gmail.com',
subject: '[Clickdi] Heartbeat',
text: `${TEMPLATE[t] || ''}`,
text: `Machine is working as expected, ${date().toString()}`,
attachments: [
{
filename: `clickdi-${date().format()}.pdf`,
Expand All @@ -61,7 +54,7 @@ export const handler: NextApiHandler<any> = api(async (req, res) => {
},
],
};

await browser.close();
await transporter.sendMail(mailOptions);
res.status(200).send('Email sent successfully');
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions controllers/og.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ export const handler: NextApiHandler = async (req, res) => {
const element = await page.$('#body');
const image = await element?.screenshot({ type: 'jpeg' });
await browser.close();
// image as response, or debug with compiledHTML


res.writeHead(200, {
'Content-Type': 'image/jpeg',
'Cache-Control': `immutable, no-transform, s-max-age=2592000, max-age=2592000`,
Expand Down

0 comments on commit 09312bb

Please sign in to comment.