Build and replace envvars, run on local transport

This commit is contained in:
Dave Smith-Hayes 2024-10-23 22:18:29 -04:00
parent 29e442677b
commit 186ca13025
8 changed files with 26 additions and 15 deletions

2
chat-app/.env.sample Normal file
View File

@ -0,0 +1,2 @@
APP_URL="chat.freedoom.party"
APP_PORT=3000

1
chat-app/.gitignore vendored
View File

@ -1,2 +1,3 @@
# deps
node_modules/
.env

0
chat-app/Dockerfile Normal file
View File

View File

@ -11,7 +11,13 @@ async function fileExists(path: string): Promise<bool> {
}
async function main() {
const results = await Bun.build({ ...config, verbose: true });
const results = await Bun.build({
...config,
verbose: true,
define: {
'process.env.APP_URL': process.env.APP_URL,
}
});
if (!results.success) {
for (const message of results.logs) {

View File

@ -1,8 +1,11 @@
export function createWebSocket() {
try {
return new WebSocket("ws://localhost:3000/chat-service");
} catch (e) {
console.error(e);
throw e;
let appUrl = process.env.APP_URL;
if (appUrl.includes('localhost')) {
appUrl = `//${appUrl}/chat-service`;
} else {
appUrl = `//${appUrl}/chat-service`;
}
return new WebSocket(appUrl);
}

View File

@ -1,8 +0,0 @@
build:
bun build.ts
clean:
rm -r static/js/*
test:
bun test

View File

@ -59,5 +59,6 @@ app.use("/*", serveStatic({ root: "/static" }));
Bun.serve({
fetch: app.fetch,
port: parseInt(process.env.APP_PORT as string) || 3000,
websocket
});

View File

@ -1721,7 +1721,13 @@ var import_mithril = __toESM(require_mithril(), 1);
// frontend/websocket.js
function createWebSocket() {
return new WebSocket("ws://localhost:3000/chat-service");
let appUrl = "localhost:3000";
if (appUrl.includes("localhost")) {
appUrl = `//${appUrl}/chat-service`;
} else {
appUrl = `//${appUrl}/chat-service`;
}
return new WebSocket(appUrl);
}
// frontend/index.js