diff --git a/main.ts b/main.ts
index ded6792..8e4df17 100644
--- a/main.ts
+++ b/main.ts
@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
-*/
+ */
import { getVersion } from "./utils/app.ts";
@@ -26,39 +26,41 @@ 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 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");
- switch(format) {
- case "json": {
- return new Response(JSON.stringify({ ip: clientIpAddress }), {
- headers: {
- "content-type": "application/json",
- },
- });
- }
- case "jsonp": {
- const parameter = JSON.stringify({ ip: clientIpAddress });
- const callback = url.searchParams.get("callback") || "callback";
- return new Response(`${callback}(${parameter});`, {
- headers: {
- "content-type": "application/javascript",
- },
- });
- }
- default: {
- return new Response(clientIpAddress);
- }
+ switch (format) {
+ case "json": {
+ return new Response(JSON.stringify({ ip: clientIpAddress }), {
+ headers: {
+ "content-type": "application/json",
+ },
+ });
+ }
+ case "jsonp": {
+ const parameter = JSON.stringify({ ip: clientIpAddress });
+ const callback = url.searchParams.get("callback") || "callback";
+ return new Response(`${callback}(${parameter});`, {
+ headers: {
+ "content-type": "application/javascript",
+ },
+ });
+ }
+ default: {
+ 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("IpMe - A self-hosted API for obtaining your public IP address.");
console.log(`Version: ${getVersion()}`);
-console.log("Source Code: https://code.fosterhangdaan.com/foster/ipme")
-console.log("License: GNU AGPL (version 3 or later)")
+console.log("Source Code: https://code.fosterhangdaan.com/foster/ipme");
+console.log("License: GNU AGPL (version 3 or later)");
Deno.serve({ port }, handler);
diff --git a/utils/app.ts b/utils/app.ts
index f5eb118..efb9329 100644
--- a/utils/app.ts
+++ b/utils/app.ts
@@ -14,7 +14,7 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
-*/
+ */
import version from "../version.ts";