Skip to content

Commit 57cb582

Browse files
committed
Simplify env logic
1 parent 75c8ff8 commit 57cb582

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

.env.defaults

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
APP_PORT=3000
22

3-
UPSTREAM_RELAY=localhost:7777
4-
UPSTREAM_HTTPS=false
3+
UPSTREAM_RELAY=ws://localhost:7777
54

65
UPSTREAM_RAW_URL=wss://example.com
76

.env.sample

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
APP_PORT=3000
22

3-
UPSTREAM_RELAY=localhost:7777
4-
UPSTREAM_HTTPS=false
3+
UPSTREAM_RELAY=ws://localhost:7777
54

65
UPSTREAM_RAW_URL=wss://example.com
76

scripts/serve.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ dotenv.loadSync({ export: true });
44

55
const APP_PORT = Number(Deno.env.get('APP_PORT')) || 3000;
66
const UPSTREAM_RELAY = Deno.env.get('UPSTREAM_RELAY');
7-
const UPSTREAM_HTTPS = Deno.env.get('UPSTREAM_HTTPS') === 'true' ? true : false;
7+
if (UPSTREAM_RELAY == undefined) {
8+
Deno.exit(1);
9+
}
810
const UPSTREAM_RAW_URL = new URL(Deno.env.get('UPSTREAM_RAW_URL') || 'ws://localhost:3000').href;
911

10-
const UPSTREAM_URL_WS = `${UPSTREAM_HTTPS ? 'wss://' : 'ws://'}${UPSTREAM_RELAY}`;
11-
const UPSTREAM_URL_HTTP = `${UPSTREAM_HTTPS ? 'https://' : 'http://'}${UPSTREAM_RELAY}`;
12+
const UPSTREAM_URL_HTTP = UPSTREAM_RELAY?.replace('wss://', 'https://').replace('ws://', 'http://');
1213

1314
const appendNip42Proxy = async ({ upstreamHost }: { upstreamHost: string }): Promise<Response> => {
1415
const response = await fetch(new URL(upstreamHost).href, {
@@ -76,7 +77,7 @@ Deno.serve(
7677

7778
const stash = new Map<string, nostrTools.Event[]>();
7879

79-
const pfortner = pfortnerInit(UPSTREAM_URL_WS, {
80+
const pfortner = pfortnerInit(UPSTREAM_RELAY, {
8081
clientIp,
8182
sendAuthOnConnect: true,
8283
upstreamRawAddress: UPSTREAM_RAW_URL,

0 commit comments

Comments
 (0)