How to call "this" shop in my express route?

Solved
Excursionist
20 3 2
I am storing the accessToken and shop in my MySQL table in the  '/shopify/callback' route.
 
I want to call on shop in my route '/app/get/metafield' to do a lookup in my table and pull the correct record that matches the shop.
Ie: If shop = shop then show record...
 
How do I call on 'this' shop within the '/app/get/metafield' route to then compare the shop in my MySQL table?

 

app.get('/shopify/callback', function (req, res, next) {
let shop = req.query.shop;
// code to store to MySQL table
})

app.get('/app/get/metafield', function (req,res,next) {
// do I do this ? // let shop = req.query.shop;
}
})
 
0 Likes

Success.

Excursionist
20 3 2

I did some experimenting last night and found that you can call the shop variable in any route as:

 

 

let shop = req.query.shop;

 

 

I think this will work as long as the following is true:

 

 

// INSTALL ROUTE
app.get('/shopify', (req, res) => { const shop = req.query.shop; })

 

 

So for the example I posted earlier this is how I ended up coding it:

 

 

// INSTALL ROUTE
app.get('/shopify', (req, res) => { const shop = req.query.shop; // add code to insert shop variable into MySQL table // })
// GET METAFIELD ROUTE app.get('/app/get/metafield', function (req,res,next) { let shop = req.query.shop; // add code to get MySQL record pertaining to this shop // } })

 

 

0 Likes