New Shopify Certification now available: Liquid Storefronts for Theme Developers

Mapping virtual store endpoint

Solved
MatBitt
Shopify Partner
3 1 1

I need to map a specific endpoint on my shopify virtual store. There's a QRcode on a physical card that redirects to my shopify store with an id as a parameter (i.e. www.my-store.com/card/ABDK-GTR). The thing is that each card has its own id, so I need to map the endpoint /card/{id} and use this id to redirect to another site (i.e. www.another-website.com/path/ABDK-GTR). Is there a way I can do that?

I've tried implementing a shopify app with a controller in node.js

 

 

import express from "express";
const app = express();

...

app.get('/card/:id', (req, res) =>{
  const cardId = req.params.id;

  const redirectUrl = 'https://www.another-website.com/path/' + cardId;
  res.redirect(redirectUrl);
})

...

 

 

but got no success with it. When I run my app everything goes just fine, if I try to access in a local server via ngrok and pass a ID, it does what it should do (https://d584-201-73-178-100.ngrok-free.app/card/ABC-DEF redirects to https://www.another-website.com/path/ABC-DEF). But then I installed this app on the virtual store to map the endpoint in the store (www.my-store.com/card/{id}) and it just doesn't work.

Am I missing something? Is there another way of doing this? Any help would be appreciated!

Accepted Solution (1)
MatBitt
Shopify Partner
3 1 1

This is an accepted solution.

In case someone in the future has the same problem, I didn't find a way to solve it by implementing an app. So I wrote some javascript inside theme.liquid, that will run in any page the user's at. Basically it takes the current url, verifies if it matches to the one I'm analyzing, and then redirect in positive case.

View solution in original post

Reply 1 (1)
MatBitt
Shopify Partner
3 1 1

This is an accepted solution.

In case someone in the future has the same problem, I didn't find a way to solve it by implementing an app. So I wrote some javascript inside theme.liquid, that will run in any page the user's at. Basically it takes the current url, verifies if it matches to the one I'm analyzing, and then redirect in positive case.