Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "stoat-for-web",
"version": "0.9.1",
"description": "Stoat for Web: frontend software for Stoat",
"dependencies": {
"dotenv": "^17.4.2"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"eslint": "^9.26.0",
Expand Down
39 changes: 39 additions & 0 deletions packages/client/app-config.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { PluginOption } from "vite";

//Load .env file
import dotenv from "dotenv";
dotenv.config({ quiet: true });

import CONFIGURATION, { AppConfig } from "./components/common/lib/env";

//Data for public config endpoint
const appCfg = JSON.stringify({
api: CONFIGURATION.DEFAULT_API_URL,
gifbox: CONFIGURATION.DEFAULT_GIFBOX_URL,
} as AppConfig);

export default function appConfigPlugin(): PluginOption {
return {
name: "app-config",
//For dev / serve mode
configureServer(server) {
server.middlewares.use("/stoat-config.json", (_, res) => {
res.writeHead(200, {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
});
res.end(appCfg);
});
},
//For static build
buildStart() {
//TODO: This throws warning "context method emitFile() is not supported in serve mode. This plugin is likely not vite-compatible."
//Need to add a conditional and detect serve mode somehow
this.emitFile({
fileName: "stoat-config.json",
source: appCfg,
type: "asset",
});
},
};
}
15 changes: 14 additions & 1 deletion packages/client/components/common/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
export const STOAT_API = "https://api.stoat.chat";

//Run in NodeJS mode
if (!("env" in import.meta))
(import.meta as { env: NodeJS.ProcessEnv }).env = process.env;

/** App `/.stoat-config` endpoint response */
export interface AppConfig {
api: string;
gifbox: string;
}

const DEFAULT_API_URL =
(import.meta.env.DEV ? import.meta.env.VITE_DEV_API_URL : undefined) ??
(import.meta.env.VITE_API_URL as string) ??
"https://stoat.chat/api";
STOAT_API;

export default {
/**
Expand All @@ -22,6 +34,7 @@ export default {
"https://revolt.chat/api",
// ... and now:
"https://stoat.chat/api",
STOAT_API,
].includes(DEFAULT_API_URL),
/**
* What WS server to connect to by default.
Expand Down
2 changes: 2 additions & 0 deletions packages/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { VitePWA } from "vite-plugin-pwa";
import solidPlugin from "vite-plugin-solid";
import solidSvg from "vite-plugin-solid-svg";

import appConfigPlugin from "./app-config.plugin";
import codegenPlugin from "./codegen.plugin";

const base = process.env.BASE_PATH ?? "/";
Expand All @@ -19,6 +20,7 @@ export default defineConfig({
Inspect(),
devtools(),
codegenPlugin(),
appConfigPlugin(),
babelMacrosPlugin(),
linguiSolidPlugin(),
solidPlugin(),
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading