Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow send custom location from server #3153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ export async function getLocation(ip: string, req: NextApiRequestCollect) {
return;
}

const customHeader = String(process.env.CLIENT_IPCOUNTRY_HEADER).toLowerCase();

if (customHeader !== 'undefined' && req.headers[customHeader]) {
const reginCodeHeader = String(process.env.CLIENT_REGION_CODE_HEADER).toLowerCase();
const cityHeader = String(process.env.CLIENT_CITY_HEADER).toLowerCase();

const country = req.headers[customHeader];
const subdivision1 = req.headers[reginCodeHeader];
const city = req.headers[cityHeader];

return {
country,
subdivision1: getRegionCode(country, subdivision1),
city,
};
}

// Cloudflare headers
if (req.headers['cf-ipcountry']) {
const country = safeDecodeCfHeader(req.headers['cf-ipcountry']);
Expand Down