Hi I am trying to use a fetch on pages/products.js as follows, somehow it its not getting to my route but redirected to /auth. Any idea how i can implement a
GET https://fb54327b9b9a.ngrok.io/auth 400
/pages/products.js
import { Card, Layout, Page } from ‘@shopify/polaris’;
import React from ‘react’;
import ProdctList from ‘../components/rest/ProductList’;
class Prodcts extends React.Component {
state = {
items:
}
componentDidMount(){
fetch(‘/api/getProducts’, {method: ‘get’})
.then((res) => {
const res2 = res.clone().text();
console.log(res2);
res.json();
})
.then(items => {
this.setState({items})
});
}
render() {
let products = this.state.items.products;
return (
<Layout.AnnotatedSection
title=“Products”
description=“List of products in this section”>
</Layout.AnnotatedSection>
)
}
}
export default Prodcts;
server.js
//=======================================================================//
// GET Products Route
//=======================================================================//
router.get(‘/api/getProducts’, verifyRequest(), async (ctx, res) => {
console.log(“test”);
const shop = ctx.session;
const accessToken = ctx.cookies.get(‘accessToken’);
const response = await products.getProducts(accessToken, shop);
ctx.body = response.data;
ctx.res.statusCode = 200;
});