style: Fix formatting
This commit is contained in:
parent
82ec8f8f6f
commit
d1a43f56ba
2 changed files with 28 additions and 26 deletions
52
main.ts
52
main.ts
|
@ -14,7 +14,7 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getVersion } from "./utils/app.ts";
|
import { getVersion } from "./utils/app.ts";
|
||||||
|
|
||||||
|
@ -26,39 +26,41 @@ const handler = (req: Request): Response => {
|
||||||
const rootMatch = ROOT_PATTERN.exec(req.url);
|
const rootMatch = ROOT_PATTERN.exec(req.url);
|
||||||
|
|
||||||
if (rootMatch && req.method === "GET") {
|
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 url = new URL(req.url);
|
||||||
const format = url.searchParams.get("format");
|
const format = url.searchParams.get("format");
|
||||||
|
|
||||||
switch(format) {
|
switch (format) {
|
||||||
case "json": {
|
case "json": {
|
||||||
return new Response(JSON.stringify({ ip: clientIpAddress }), {
|
return new Response(JSON.stringify({ ip: clientIpAddress }), {
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case "jsonp": {
|
case "jsonp": {
|
||||||
const parameter = JSON.stringify({ ip: clientIpAddress });
|
const parameter = JSON.stringify({ ip: clientIpAddress });
|
||||||
const callback = url.searchParams.get("callback") || "callback";
|
const callback = url.searchParams.get("callback") || "callback";
|
||||||
return new Response(`${callback}(${parameter});`, {
|
return new Response(`${callback}(${parameter});`, {
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/javascript",
|
"content-type": "application/javascript",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return new Response(clientIpAddress);
|
return new Response(clientIpAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new Response("Not found", { status: 404 });
|
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(`Version: ${getVersion()}`);
|
||||||
console.log("Source Code: https://code.fosterhangdaan.com/foster/ipme")
|
console.log("Source Code: https://code.fosterhangdaan.com/foster/ipme");
|
||||||
console.log("License: GNU AGPL (version 3 or later)")
|
console.log("License: GNU AGPL (version 3 or later)");
|
||||||
|
|
||||||
Deno.serve({ port }, handler);
|
Deno.serve({ port }, handler);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import version from "../version.ts";
|
import version from "../version.ts";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue