CORS and request parsing in Begin.com functions

1. CORS

Access to fetch at 'http://localhost:3333/wiki/wiki' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
"Access-Control-Allow-Origin": "*"
let arc = require('@architect/functions');
async function http(req) {
return {
cors: true
}
}
exports.handler = arc.http.async(http);

2. Request parsing

exports.handler = async function http(req) {
let body = arc.http.helpers.bodyParser(req);
JSON.parse(Buffer.from(body, 'base64').toString('ascii'));
fetch(ROOT + "/wiki", {
method: "POST",
body: JSON.stringify({
title,
page: newContent
}),
mode: "no-cors",
headers: {
"Content-Type": "application/json"
}
})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store