import querystring from 'querystring' ; import type { NextApiRequest , NextApiResponse } from 'next' ; import redirectionPage from './redirection-page' ; export default function createTopLevelRedirect ( apiKey , path , appUrl ) { return function topLevelRedirect ( req , res ) { const query = req . query as Record < string , string > ; const params = { shop : query . shop } ; const queryString = querystring . stringify ( params ) ; res . send ( redirectionPage ( { origin : query . shop , redirectTo : `${ appUrl }${ path }?${ queryString }` , apiKey , } ) ) ; } ; }