import querystring from 'querystring' ; import { Context } from 'koa' ; import redirectionPage from './redirection-page' ; export default function createTopLevelRedirect ( apiKey , path ) { return function topLevelRedirect ( ctx ) { const { host , query } = ctx ; const { shop } = query ; const params = { shop } ; const queryString = querystring . stringify ( params ) ; ctx . body = redirectionPage ( { origin : shop , redirectTo : `https://${ host }${ path }?${ queryString }` , apiKey , } ) ; } ; }