Version 0.2.0:
commit 54ef9b63c845b58ecce041ed8e189922f0383ee3 Author: Foster Hangdaan <foster@hangdaan.email> Date: Mon Nov 13 18:20:32 2023 -0500 fix: Minor update to app description commit 823ba6fa0a7a13ccd5e4c83f5f6825f4a53f5e2c Author: Foster Hangdaan <foster@hangdaan.email> Date: Mon Nov 13 18:12:41 2023 -0500 feat: add endpoint for obtaining IPv4 address commit 2e265aee602ccde515852b7a98bd1b92d9a42447 Author: Foster Hangdaan <foster@hangdaan.email> Date: Mon Nov 13 15:42:08 2023 -0500 Bump version to 0.2.0
This commit is contained in:
parent
1ce8b53b50
commit
19c6ecd7ff
6 changed files with 32 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
||||||
# IpMe - A self-hosted API for obtaining a public IP address.
|
# IpMe - A self-hosted API for obtaining your public IP address.
|
||||||
# Copyright (C) 2023 Foster Hangdaan <foster@hangdaan.email>
|
# Copyright (C) 2023 Foster Hangdaan <foster@hangdaan.email>
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
* About
|
* About
|
||||||
|
|
||||||
A self-hosted API for obtaining public IP address.
|
A self-hosted API for obtaining your public IP address.
|
||||||
|
|
||||||
* Contributing
|
* Contributing
|
||||||
|
|
||||||
|
|
30
main.ts
30
main.ts
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* IpMe - A self-hosted API for obtaining a public IP address.
|
* IpMe - A self-hosted API for obtaining your public IP address.
|
||||||
* Copyright (C) 2023 Foster Hangdaan <foster@hangdaan.email>
|
* Copyright (C) 2023 Foster Hangdaan <foster@hangdaan.email>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -20,9 +20,33 @@ import { getVersion } from "./utils/app.ts";
|
||||||
|
|
||||||
const port = Number(Deno.env.get("PORT")) || 8000;
|
const port = Number(Deno.env.get("PORT")) || 8000;
|
||||||
|
|
||||||
const handler = (_req: Request): Response => {
|
const ROOT_PATTERN = new URLPattern({ pathname: "/" });
|
||||||
return new Response("Hello world");
|
|
||||||
|
const handler = (req: Request): Response => {
|
||||||
|
const rootMatch = ROOT_PATTERN.exec(req.url);
|
||||||
|
|
||||||
|
if (rootMatch && req.method === "GET") {
|
||||||
|
const clientIpAddress = req.headers.get("x-forwarded-for")?.split(",").shift() || req.headers.get("host");
|
||||||
|
const url = new URL(req.url);
|
||||||
|
const format = url.searchParams.get("format");
|
||||||
|
|
||||||
|
if (format === "json") {
|
||||||
|
return new Response(JSON.stringify({ ip: clientIpAddress }), {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new Response(clientIpAddress);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return new Response("Not found", { status: 404 });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("IpMe - A self-hosted API for obtaining your public IP address.")
|
||||||
console.log(`Version: ${getVersion()}`);
|
console.log(`Version: ${getVersion()}`);
|
||||||
|
console.log("Source Code: https://code.fosterhangdaan.com/foster/ipme")
|
||||||
|
console.log("License: GNU AGPL (version 3 or later)")
|
||||||
|
|
||||||
Deno.serve({ port }, handler);
|
Deno.serve({ port }, handler);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* IpMe - A self-hosted API for obtaining a public IP address.
|
* IpMe - A self-hosted API for obtaining your public IP address.
|
||||||
* Copyright (C) 2023 Foster Hangdaan <foster@hangdaan.email>
|
* Copyright (C) 2023 Foster Hangdaan <foster@hangdaan.email>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* IpMe - Self-hosted API for obtaining a public IP address.
|
* IpMe - A self-hosted API for obtaining your public IP address.
|
||||||
* Copyright (C) 2023 Foster Hangdaan <foster@hangdaan.email>
|
* Copyright (C) 2023 Foster Hangdaan <foster@hangdaan.email>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
const version = "0.1.0";
|
const version = "0.2.0";
|
||||||
export default version;
|
export default version;
|
||||||
|
|
Loading…
Reference in a new issue