2021-02-25 16:39:01 -05:00
const commerce = require ( './commerce.config.json' )
2022-02-01 14:14:05 -05:00
const { withCommerceConfig , getProviderName } = require ( './commerce-config' )
2021-02-24 21:55:45 -05:00
2021-03-29 17:03:45 -06:00
const provider = commerce . provider || getProviderName ( )
2022-02-01 14:14:05 -05:00
const isBC = provider === '@vercel/commerce-bigcommerce'
const isShopify = provider === '@vercel/commerce-shopify'
const isSaleor = provider === '@vercel/commerce-saleor'
const isSwell = provider === '@vercel/commerce-swell'
const isVendure = provider === '@vercel/commerce-vendure'
2021-02-24 21:55:45 -05:00
module . exports = withCommerceConfig ( {
commerce ,
i18n : {
locales : [ 'en-US' , 'es' ] ,
defaultLocale : 'en-US' ,
} ,
rewrites ( ) {
return [
2021-09-24 13:42:09 -03:00
( isBC || isShopify || isSwell || isVendure || isSaleor ) && {
2021-02-24 21:55:45 -05:00
source : '/checkout' ,
2022-10-30 20:41:21 +02:00
destination : '/api/commerce/checkout' ,
2021-02-24 21:55:45 -05:00
} ,
// The logout is also an action so this route is not required, but it's also another way
// you can allow a logout!
isBC && {
source : '/logout' ,
2021-06-01 03:18:10 -05:00
destination : '/api/logout?redirect_to=/' ,
2021-02-24 21:55:45 -05:00
} ,
2021-05-27 23:06:56 +02:00
// For Vendure, rewrite the local api url to the remote (external) api url. This is required
// to make the session cookies work.
isVendure &&
process . env . NEXT _PUBLIC _VENDURE _LOCAL _URL && {
source : ` ${ process . env . NEXT _PUBLIC _VENDURE _LOCAL _URL } /:path* ` ,
destination : ` ${ process . env . NEXT _PUBLIC _VENDURE _SHOP _API _URL } /:path* ` ,
} ,
2021-05-31 23:32:10 -03:00
] . filter ( Boolean )
2021-02-24 21:55:45 -05:00
} ,
2022-09-19 08:14:49 +03:00
// Avoid Module not found: ESM packages (supports-color) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals
experimental : {
esmExternals : 'loose' ,
} ,
2021-02-24 21:55:45 -05:00
} )
2021-03-29 17:03:45 -06:00
// Don't delete this console log, useful to see the commerce config in Vercel deployments
console . log ( 'next.config.js' , JSON . stringify ( module . exports , null , 2 ) )