I can't get Shopify to return a response when I try to sent a request via Express through NGINX

developerfilip
New Member
5 0 0

I'm just trying to fetch a simple customer list with a GET request.

It works perfectly on localhost, but does not work on my server machine. The problem is that if I try to send other API requests to any public API through my server it works - so I'm starting to doubt it's actually a problem with my nginx and more of an issue with the Shopify API itself.

I assumed it might be my code, so I tried to send the same request via my machine IP thought postman, but also same pending and timeout issue persists.

I'm sending my requests over a http connection on my server. Not sure if that could be the issue and Shopify blocking it? 

Below is my code for the express server:

 

const express = require('express');
const axios = require('axios');

require('dotenv').config();

const app = express();
const port = process.env.PORT || 6000;

app.use(express.json());
app.use(express.urlencoded({
  extended: true
}));

app.get('/api/add_customer', async (req, res) => {

  let shopifyUrl = 'https://' + process.env.SHOPIFY_URL + '/admin/api/2021-07/customers.json';

  try {
    const response = await axios.get(shopifyUrl, {
      headers: {
        'X-Shopify-Access-Token': process.env.SHOPIFY_PASS,
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': '*'
      }
    });

    console.log('RESPONSE: ', response);

    res.send("All good");

  } catch (err) {
    res.send(err);
  }

});

app.listen(port, () => console.log(`Listening on port ${port}`));

 

 

Here is my NGINX config file:

 

 

server {
        listen 80;
        listen [::]:80;

        server_name SERVER_IP_ADDRESS;

        location / {
                root /var/www/html;
                index index.html index.htm index.nginx-debian.html;
                try_files $uri /index.html$is_args$args =404;
        }

        location /api {
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_pass http://localhost:6000;
                proxy_cache_bypass $http_upgrade;
        }
}

 

 

My webpack devServer config:

Could this be the issue that would mess with my NGINX proxy?

 

devServer: {
    port: 3000,
    watchContentBase: true,
    historyApiFallback: true,
    proxy: {
      "/api": "http://localhost:6000",
      // "secure": false,
      // "changeOrigin": true
    }
  },

 

 

Thanks for all the help!

0 Likes