generated from template/slidev-template
update
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
const baseURLv4 = 'https://4.ipw.cn/';
|
||||
const baseURLv6 = 'https://6.ipw.cn/';
|
||||
|
||||
|
||||
import { app } from './app.ts';
|
||||
|
||||
|
||||
app.route({
|
||||
path: 'ip',
|
||||
key: 'v4',
|
||||
@@ -12,7 +10,7 @@ app.route({
|
||||
}).define(async (ctx) => {
|
||||
const response = await fetch(baseURLv4);
|
||||
const ip = (await response.text()).trim();
|
||||
if(!isIpv4(ip)) {
|
||||
if (!isIpv4(ip)) {
|
||||
ctx.throw?.('获取地址失败');
|
||||
}
|
||||
ctx.body = { ip };
|
||||
@@ -25,7 +23,7 @@ app.route({
|
||||
}).define(async (ctx) => {
|
||||
const response = await fetch(baseURLv6);
|
||||
const ip = (await response.text()).trim();
|
||||
if(!isIpv6(ip)) {
|
||||
if (!isIpv6(ip)) {
|
||||
ctx.throw?.('获取地址失败');
|
||||
}
|
||||
ctx.body = { ip };
|
||||
@@ -38,4 +36,5 @@ export const isIpv6 = (ip: string): boolean => {
|
||||
|
||||
export const isIpv4 = (ip: string): boolean => {
|
||||
return ip.split('.').length === 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user