Description
Directory structure:
src/
├── app/
│ └──actions.ts
next-i18next.config.js
next.config.js
//next-i18next.config.js
/**
- @type {import('next-i18next').UserConfig}
*/
const path = require('path');
module.exports = {
i18n: {
defaultLocale: 'zh',
locales: ['en', 'zh'],
},
};
//next.config.js
const { withStoreConfig } = require("./store-config")
const store = require("./store.config.json")
/** @type {import('next').NextConfig} */
const { i18n } = require('./next-i18next.config');
/**
- @type {import('next').NextConfig}
*/
const nextConfig = withStoreConfig({
// i18n,
features: store.features,
reactStrictMode: true,
images: {
remotePatterns: [
{
protocol: "http",
hostname: "localhost",
},
{
protocol: "https",
hostname: "medusa-public-images.s3.eu-west-1.amazonaws.com",
},
{
protocol: "https",
hostname: "medusa-server-testing.s3.amazonaws.com",
},
{
protocol: "https",
hostname: "medusa-server-testing.s3.us-east-1.amazonaws.com",
},
],
},
})
console.log("next.config.js", JSON.stringify(module.exports, null, 2))
module.exports = nextConfig
//actions.ts
"use server"
import { revalidateTag } from "next/cache"
import { cookies } from "next/headers"
import { redirect } from "next/navigation"
import { getRegion, updateCart } from "@lib/data"
/**
- Updates the countrycode param and revalidates the regions cache
- @param regionId
- @param countryCode
*/
export async function updateRegion(countryCode: string, currentPath: string) {
const cartId = cookies().get("_medusa_cart_id")?.value
const region = await getRegion(countryCode)
if (!region) {
return null
}
try {
if (cartId) {
await updateCart(cartId, { region_id: region.id })
revalidateTag("cart")
}
revalidateTag("regions")
revalidateTag("products")
} catch (e) {
return "Error updating region"
}
console.log("1111")
redirect(/${countryCode}${currentPath}
)
}
export async function resetOnboardingState(orderId: string) {
cookies().set("_medusa_onboarding", "false", { maxAge: -1 })
redirect(http://localhost:7001/a/orders/${orderId}
)
}
The expected result should be yarn dev running and automatically jumping to http://localhost:8000/zh after opening http://localhost:8000