28 lines
877 B
JavaScript
28 lines
877 B
JavaScript
import { headers } from "next/headers";
|
|
|
|
// Data
|
|
import citiesData from "@/data/city.json";
|
|
import statesData from "@/data/state.json";
|
|
|
|
import { ROOT_CITY_ID, isRootCity } from "@/lib/rootCity";
|
|
export { ROOT_CITY_ID, isRootCity };
|
|
|
|
export async function getStateInfo() {
|
|
const headersList = await headers();
|
|
|
|
const host = headersList.get("host") || "";
|
|
const subdomain = host.split(".")[0];
|
|
|
|
// Match city by domain (supports both full domain and subdomain)
|
|
const matchedCity = citiesData.find((city) => {
|
|
const cityDomain = city.domain.split(".")[0]; // Extract subdomain from domain (e.g., "yasuj-nobat" from "yasuj-nobat.ir")
|
|
return cityDomain === subdomain;
|
|
});
|
|
|
|
const matchedState =
|
|
matchedCity &&
|
|
statesData.find((state) => state.id === matchedCity.province_id);
|
|
|
|
return { matchedCity, matchedState, isRoot: isRootCity(matchedCity) };
|
|
}
|