generated from Ideal-Media-Solutions-LLC/client-project-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Augment req/res objects (fix github.com/vercel/next.js/issues/21749)
- Loading branch information
Showing
6 changed files
with
144 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
import handler from '../../handler'; | ||
import { locateIP } from '../../db/location'; | ||
|
||
/** | ||
* @param {import('next').NextApiRequest} req | ||
* @param {import('next').NextApiResponse} res | ||
*/ | ||
const GET = async function GET(req, res) { | ||
/** @type {string} */ | ||
let ip = req.socket.remoteAddress; | ||
const lastColon = ip.lastIndexOf(':'); | ||
if (lastColon !== -1 && ip.indexOf('.') !== -1) { // mixed IPv4 and IPv6 | ||
ip = ip.substring(0, lastColon); | ||
} | ||
const location = await locateIP(ip); | ||
res.status(200).json(location); | ||
}; | ||
|
||
export default handler({ GET }); | ||
export default handler({ | ||
async GET(req, res) { | ||
let ip = req.socket.remoteAddress; | ||
const lastColon = ip.lastIndexOf(':'); | ||
if (lastColon !== -1 && ip.indexOf('.') !== -1) { // mixed IPv4 and IPv6 | ||
ip = ip.substring(0, lastColon); | ||
} | ||
const location = await locateIP(ip); | ||
res.status(200).json(location); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters