-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use ip endpoint to fetch from non-https endpoint
- Loading branch information
1 parent
cdfacef
commit e3d116a
Showing
4 changed files
with
30 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import { IpAddressInfo } from "../../shared/types"; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
if (req.method !== 'GET') { | ||
res.setHeader('Allow', ['GET']) | ||
res.status(405).json({ | ||
error: { message: `Method ${req.method} Not Allowed` } | ||
}) | ||
} | ||
|
||
const response = await fetch('http://ip-api.com/json/') | ||
const data = await response.json() | ||
const { status, query, ...rest } = data | ||
|
||
if (status !== 'success') { | ||
res.status(500).json({ error: 'Failed to get IP address info' }) | ||
} | ||
const ipInfo = { ...rest, ipAddress: query } as IpAddressInfo | ||
|
||
res.status(200).json({ ...ipInfo }) | ||
} |
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