make more aspects of API & UI hosting configurable

This is necessary to create proper dev & production builds of the app.
This commit is contained in:
ducklet 2021-08-05 19:18:51 +02:00
parent ebdf3a39f3
commit 9acd534706
4 changed files with 13 additions and 8 deletions

View file

@ -1,3 +1,3 @@
export default { export default {
api_url: "http://localhost:8000/api/v1/", api_url: `${process.env.API_URL}v1/`,
} }

View file

@ -3,5 +3,11 @@ import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [vue()] base: process.env.BASE_URL || "/",
define: {
"process.env.API_URL": JSON.stringify(
process.env.API_URL || "http://localhost:8000/api/",
),
},
plugins: [vue()],
}) })

View file

@ -16,4 +16,6 @@ config_path = os.getenv("UNWIND_CONFIG", datadir / "config.toml")
_config = toml.load(config_path) _config = toml.load(config_path)
api_credentials = _config["api"]["credentials"] api_base = _config["api"].get("base", "/api/")
api_cors = _config["api"].get("cors", "*")
api_credentials = _config["api"].get("credentials", {})

View file

@ -627,7 +627,7 @@ def create_app():
on_startup=[open_connection_pool], on_startup=[open_connection_pool],
on_shutdown=[close_connection_pool], on_shutdown=[close_connection_pool],
routes=[ routes=[
Mount("/api/v1", routes=route.registered), Mount(f"{config.api_base}v1", routes=route.registered),
], ],
middleware=[ middleware=[
Middleware(ResponseTimeMiddleware, header_name="Unwind-Elapsed"), Middleware(ResponseTimeMiddleware, header_name="Unwind-Elapsed"),
@ -638,10 +638,7 @@ def create_app():
), ),
Middleware( Middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=[ allow_origins=[config.api_cors],
# "*",
"http://localhost:3000",
],
allow_credentials=True, allow_credentials=True,
allow_methods=["*"], allow_methods=["*"],
allow_headers=["*"], allow_headers=["*"],