Skip to content

Instantly share code, notes, and snippets.

@KameronKales
Created May 26, 2019 02:21
Show Gist options
  • Save KameronKales/353d583a223215a6af2d655a3fc54565 to your computer and use it in GitHub Desktop.
Save KameronKales/353d583a223215a6af2d655a3fc54565 to your computer and use it in GitHub Desktop.
Post request sent from JS widget
const { json, send } = require("micro");
const cors = require("cors");
module.exports = async (req, res) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
const body = await json(req);
console.log(cors);
send(res, 200, body);
};
function save(data, aCallback) {
var cookie = data.cookies;
var user_settings = data.user_settings;
var page_view = data.page_view;
var user_data = { user_settings: user_settings, page_view: page_view, cookie: cookie };
console.log( \\`This is our user_data object from the logger function sending to our stream API\\`, user_data );
var api = API + "/email";
console.log(\\`This is our api\\`, api);
axios .post(api, user_data)
.then(response => { console.log(response); })
.catch(err => { console.log(err); });
aCallback(data); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment