Skip to content

Commit c6bd17e

Browse files
committed
add get public ip
1 parent 10e3b3c commit c6bd17e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Common/Location.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAxios } from '../Tools/Axios';
2-
import { replaceAll } from '../Common/Helpers';
2+
import { replaceAll } from './Helpers';
33
import { Input, output, Output } from '@pulumi/pulumi';
44

55
interface LocationResult {
@@ -32,5 +32,17 @@ const getLocationString = async (possibleName: string) => {
3232
return location?.displayName;
3333
};
3434

35-
export const getLocation = (possibleName: Input<string>): Output<string> =>
35+
export const getLocation = (
36+
possibleName: Input<string>
37+
): Output<string | undefined> =>
3638
output(possibleName).apply(async (l) => await getLocationString(l));
39+
40+
export const getMyPublicIpAddress = async (): Promise<string | undefined> => {
41+
const res = await fetch('https://api.myip.com');
42+
43+
if (res.ok) {
44+
const data = await res.json();
45+
return data.ip;
46+
}
47+
return undefined;
48+
};

tsconfig.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
"strict": true,
44
"outDir": "bin",
55
"target": "esnext",
6-
"lib": ["es2019", "esnext.array","esnext.string"],
6+
"lib": [
7+
"es2019",
8+
"esnext.array",
9+
"esnext.string",
10+
"dom"
11+
],
712
"module": "commonjs",
813
"moduleResolution": "node",
914
"sourceMap": true,

0 commit comments

Comments
 (0)