add configurable server address to webapp, remove webapp serving from server

This commit is contained in:
Elijah R 2024-07-12 14:38:49 -04:00
parent 8d04752f52
commit b515578750
3 changed files with 7 additions and 8 deletions

View file

@ -44,12 +44,6 @@ app.register(FastifyWS);
let tts = null; let tts = null;
app.register(FastifyStatic, {
root: path.dirname(fileURLToPath(import.meta.url)) + "/../../webapp/dist/",
prefix: "/",
decorateReply: true
});
if (config.tts.enabled) { if (config.tts.enabled) {
tts = new TTSClient(config.tts); tts = new TTSClient(config.tts);
app.register(FastifyStatic, { app.register(FastifyStatic, {
@ -75,7 +69,7 @@ for (let agent of config.agents) {
app.register(FastifyStatic, { app.register(FastifyStatic, {
root: path.resolve(config.chat.agentsDir), root: path.resolve(config.chat.agentsDir),
prefix: "/api/agents/", prefix: "/api/agents/",
decorateReply: false, decorateReply: true,
}); });
app.get("/api/agents", (req, res) => { app.get("/api/agents", (req, res) => {

4
webapp/config.ts Normal file
View file

@ -0,0 +1,4 @@
export const Config = {
// The server address for the webapp to connect to. The below default is the same address the webapp is hosted at.
serverAddress: `${window.location.protocol}//${window.location.host}`
}

View file

@ -1,6 +1,7 @@
import { MSWindow, MSWindowStartPosition } from "./MSWindow.js"; import { MSWindow, MSWindowStartPosition } from "./MSWindow.js";
import { agentInit } from "@msagent-chat/msagent.js"; import { agentInit } from "@msagent-chat/msagent.js";
import { MSAgentClient } from "./client.js"; import { MSAgentClient } from "./client.js";
import { Config } from "../../config.js";
const elements = { const elements = {
@ -23,7 +24,7 @@ const elements = {
let Room : MSAgentClient; let Room : MSAgentClient;
function roomInit() { function roomInit() {
Room = new MSAgentClient(`${window.location.protocol}//${window.location.host}`, elements.chatView); Room = new MSAgentClient(Config.serverAddress, elements.chatView);
Room.on('close', () => { Room.on('close', () => {
for (let user of Room.getUsers()) { for (let user of Room.getUsers()) {
user.agent.remove(); user.agent.remove();