KOA route returns 404

Hoegnison
Shopify Partner
5 0 1

Hi everyone,

 

I am currently building my first shopify app. My goal is to load some user settings from a mysql data base.
So what I tried to do was to create a koa GET route where I call the db and return some data. In my component I am using getInitialProps to fetch my data.

The code looks like this:

 

CODE FOR ENDPOINT

 

var Router = require('koa-router');
var router = Router({
  prefix: '/myEndPoint'
});

var stubData= [
   {id: 101, name: "Bla"},
   {id: 102, name: "Bla"},
   {id: 103, name: "Bla"},
   {id: 104, name: "Bla"}
];

router.get('/', getData);
function *getData(next){
  console.log("test")
   this.body = stubData;
   yield next;
}

module.exports = router;

SERVER.JS

 

 

var myEndPoint = require('./server/api/my-end-point.js');
router.use(myEndPoint .routes());

router.get('*', verifyRequest(), async (ctx) => {
await handle(ctx.req, ctx.res);
ctx.respond = false;
ctx.res.statusCode = 200;
});

 

 

COMPONENT

 

 

    
static async getInitialProps(ctx) { const pageRequest = `http://localhost/myEndPoint` const res = await fetch(pageRequest,{ method: 'GET', headers: { Cookie: joinCookies(ctx) } } ) return res }

 

const joinCookies = ctx => {
    return _(getCookies(ctx))
      .map((value, key) => {
        return [key, value].join("=");
      })
      .join(";");
  };

 

But I am getting only 404s when I am calling the route. I understand that there might be an issue with the shopify auth, so I tried to copy the cookies into the HEADER object of my fetch call.

My app works fine within this crucial issue. It drives me crazy and I am stuck for days now. Is there a major flaw in my logic here. If you need the complete code hit me, I am aware that these examples might not be enough.

0 Likes
Ralph6
New Member
6 0 0

I'm stuck with this issue also, did you figure it out in the meantime?

Kind Regards,

Ralph

0 Likes