Shopify Node React index.js path not found (404) when route has prefix

Solved

Shopify Node React index.js path not found (404) when route has prefix

RobertDev
Excursionist
14 2 2

Hello,

 

As the title says I have a route prefix when I load my app: example https://my-route/prefix -> this will point to the app base URL.

The question is where can I change the path of the router in order to have a route prefix that will serve my index.js file? I am using Shopify Node React skeleton app as a base with Koa and embeding it in Shopify Admin (yes the settings for embedding are enabled).

 

Regards,

Robert

 

Accepted Solution (1)

RobertDev
Excursionist
14 2 2

This is an accepted solution.

Hello,

 

For anyone interested I found the solution. The Shopify Node React app uses .nextjs for file handling.

There is a file called next.config.js where I needed to add:

module.exports = withCSS({
    webpack: (config=> {
        const env = { API_KEY: apiKey };
        config.plugins.push(new webpack.DefinePlugin(env));
        return config;
    },
    basePath: '/shopify',
    assetPath: '/shopify'
});
 
basePath and assetPath.
 
Also in the server.js file I needed to add /shopify prefix for createShopifyAuth({ prefix: '/shopify' }) and also prefix the verify request function with the new routes like:
server.use(
        verifyRequest({
            authRoute: `${ROUTE_PREFIX}/auth`,
            fallbackRoute: `${ROUTE_PREFIX}/install`
        })
);
 
The API route paths which I had with POST needed to be prefixed with /shopify as well in server.js.
 
I hope this helps anyone!
Cheers!

View solution in original post

Reply 1 (1)

RobertDev
Excursionist
14 2 2

This is an accepted solution.

Hello,

 

For anyone interested I found the solution. The Shopify Node React app uses .nextjs for file handling.

There is a file called next.config.js where I needed to add:

module.exports = withCSS({
    webpack: (config=> {
        const env = { API_KEY: apiKey };
        config.plugins.push(new webpack.DefinePlugin(env));
        return config;
    },
    basePath: '/shopify',
    assetPath: '/shopify'
});
 
basePath and assetPath.
 
Also in the server.js file I needed to add /shopify prefix for createShopifyAuth({ prefix: '/shopify' }) and also prefix the verify request function with the new routes like:
server.use(
        verifyRequest({
            authRoute: `${ROUTE_PREFIX}/auth`,
            fallbackRoute: `${ROUTE_PREFIX}/install`
        })
);
 
The API route paths which I had with POST needed to be prefixed with /shopify as well in server.js.
 
I hope this helps anyone!
Cheers!