How to make an AJAX call to a middleware API

New Member
3 0 0

I'm trying to make an AJAX call from the shopify frontend, I'm aware that using shopify storefront API with AJAX is a terrible idea since I would expose the credentials, so I created a Node API middleware to handle the request. 

Now I'm trying to call my personal API from the store frontend but I'm getting the  "has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource." error.

Is it possible to make any http request from the frontend?

Thank you

this is my call 


$(document).ready(function() {
        type: 'POST',
        url: 'MYAPIURL,
        dataType: "json",
        success: function(data) {


New Member
3 0 0

Well truns out the AJAX call was correct, I forgot to add this code to my node API


app.use(function(req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); 
    res.setHeader('Access-Control-Allow-Credentials', true); 
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Access-Control-Allow-Headers, X-Requested-With');