From fe446cab6ca98c3d33316d0b68fc252b1e00cc80 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 6 Feb 2020 22:02:14 +1100 Subject: [PATCH] Cleansed some cors stuff --- src/private/src/functions/mail/send.ts | 2 +- src/private/src/handler/handler.ts | 4 ++-- src/public/src/api/APIRequest.tsx | 4 ++-- src/public/src/api/SendMail.tsx | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/private/src/functions/mail/send.ts b/src/private/src/functions/mail/send.ts index 745ecb5..0b83717 100644 --- a/src/private/src/functions/mail/send.ts +++ b/src/private/src/functions/mail/send.ts @@ -52,5 +52,5 @@ export const sendMail = withHandler(async (e,c) => { Time: ${new Date().toLocaleString()} ` }); - return { statusCode: 200, body: x && x.accepted && x.accepted.length } + return { statusCode: 200, body: x && x.accepted && x.accepted.length ? true : false } }); \ No newline at end of file diff --git a/src/private/src/handler/handler.ts b/src/private/src/handler/handler.ts index 99757fa..04a99c8 100644 --- a/src/private/src/handler/handler.ts +++ b/src/private/src/handler/handler.ts @@ -47,8 +47,8 @@ export const withHandler = (callable:APICallable) => { return callable(event, context).then(d => { if(!callback) return d; - let contentType = (d.headers?d.headers['Content-Type']:null) ||'application/json'; - let json = contentType.includes('application/json'); + let contentType = (d.headers?d.headers['Content-Type']:null) || 'application/json'; + let json = contentType.indexOf('application/json') !== -1; callback(null, { ...d, diff --git a/src/public/src/api/APIRequest.tsx b/src/public/src/api/APIRequest.tsx index dbc02c3..098f608 100644 --- a/src/public/src/api/APIRequest.tsx +++ b/src/public/src/api/APIRequest.tsx @@ -1,13 +1,13 @@ export const APIRequest = (url:string, body?:object) => { return fetch(`https://api.domsplace.com/v1/${url}`, { - mode: 'no-cors', + //mode: 'no-cors', method: body ? 'POST' : 'GET', body: body ? JSON.stringify(body) : null, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } - }); + }).then(e => e.json()); } diff --git a/src/public/src/api/SendMail.tsx b/src/public/src/api/SendMail.tsx index 9250706..70437e2 100644 --- a/src/public/src/api/SendMail.tsx +++ b/src/public/src/api/SendMail.tsx @@ -2,7 +2,7 @@ import { APIRequest } from "./APIRequest"; export const sendMail = (name:string, email:string, message:string) => APIRequest('mail/send', { name, email, message -}); +}).then(e => e.body); ///@ts-ginore (globalThis as any)['sendMail' as any] = sendMail as any; \ No newline at end of file