feature/fitlien-add-cors #18
@ -26,6 +26,7 @@ const corsHandler = cors({ origin: true });
|
|||||||
export const sendEmailWithAttachment = onRequest({
|
export const sendEmailWithAttachment = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
}, async (request: Request, response: express.Response) => {
|
}, async (request: Request, response: express.Response) => {
|
||||||
|
return corsHandler(request, response, async () => {
|
||||||
try {
|
try {
|
||||||
const { toAddress, subject, message, fileUrl, fileName } = request.body;
|
const { toAddress, subject, message, fileUrl, fileName } = request.body;
|
||||||
|
|
||||||
@ -82,11 +83,14 @@ export const sendEmailWithAttachment = onRequest({
|
|||||||
logger.error('Error sending email with attachment from URL:', error);
|
logger.error('Error sending email with attachment from URL:', error);
|
||||||
response.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) });
|
response.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) });
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
export const accessFile = onRequest({
|
export const accessFile = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
}, async (request: Request, response: express.Response) => {
|
}, async (request: Request, response: express.Response) => {
|
||||||
|
return corsHandler(request, response, async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const filePath = request.query.path as string;
|
const filePath = request.query.path as string;
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
@ -117,11 +121,14 @@ export const accessFile = onRequest({
|
|||||||
logger.error('Error accessing file:', error);
|
logger.error('Error accessing file:', error);
|
||||||
response.status(500).send('Error accessing file');
|
response.status(500).send('Error accessing file');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sendEmailMessage = onRequest({
|
export const sendEmailMessage = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
}, (request: Request, response: express.Response) => {
|
}, (request: Request, response: express.Response) => {
|
||||||
|
return corsHandler(request, response, async () => {
|
||||||
|
|
||||||
const mailgun = new Mailgun(formData);
|
const mailgun = new Mailgun(formData);
|
||||||
const mailGunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
|
const mailGunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
|
||||||
|
|
||||||
@ -146,11 +153,14 @@ export const sendEmailMessage = onRequest({
|
|||||||
logger.error(err);
|
logger.error(err);
|
||||||
response.send(err);
|
response.send(err);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
export const sendSMSMessage = onRequest({
|
export const sendSMSMessage = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
}, (request: Request, response: express.Response) => {
|
}, (request: Request, response: express.Response) => {
|
||||||
|
return corsHandler(request, response, async () => {
|
||||||
|
|
||||||
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
|
const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
|
||||||
const { to, body } = request.body;
|
const { to, body } = request.body;
|
||||||
client.messages
|
client.messages
|
||||||
@ -167,6 +177,7 @@ export const sendSMSMessage = onRequest({
|
|||||||
logger.error('Error sending SMS:', error);
|
logger.error('Error sending SMS:', error);
|
||||||
response.status(500).json({ success: false, error: error.message });
|
response.status(500).json({ success: false, error: error.message });
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
interface Invitation {
|
interface Invitation {
|
||||||
@ -180,6 +191,7 @@ export const notifyInvitation = onDocumentCreated({
|
|||||||
document: 'notifications/{notificationId}',
|
document: 'notifications/{notificationId}',
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
}, async (event: any) => {
|
}, async (event: any) => {
|
||||||
|
|
||||||
const invitation = event.data?.data() as Invitation;
|
const invitation = event.data?.data() as Invitation;
|
||||||
const invitationId = event.params.invitationId;
|
const invitationId = event.params.invitationId;
|
||||||
|
|
||||||
@ -343,6 +355,8 @@ export const createCashfreeOrder = onRequest({
|
|||||||
export const verifyCashfreePayment = onRequest({
|
export const verifyCashfreePayment = onRequest({
|
||||||
region: '#{SERVICES_RGN}#'
|
region: '#{SERVICES_RGN}#'
|
||||||
}, async (request: Request, response: express.Response) => {
|
}, async (request: Request, response: express.Response) => {
|
||||||
|
return corsHandler(request, response, async () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const orderId = request.body.order_id || request.query.order_id;
|
const orderId = request.body.order_id || request.query.order_id;
|
||||||
|
|
||||||
@ -394,4 +408,5 @@ export const verifyCashfreePayment = onRequest({
|
|||||||
details: error.response?.data || error.message
|
details: error.response?.data || error.message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user