mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2026-02-25 02:20:17 +00:00
✨ into shared compose project
- vite can proxy requests to the api in dev mode - no more CORS needed in api - static api_baseurl in axios config
This commit is contained in:
parent
c838f79e66
commit
005bb31fca
6 changed files with 39 additions and 30 deletions
14
.devcontainer/docker_compose.yml
Normal file
14
.devcontainer/docker_compose.yml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
name: advent22
|
||||||
|
|
||||||
|
services:
|
||||||
|
api:
|
||||||
|
image: mcr.microsoft.com/devcontainers/python:3-3.14-trixie
|
||||||
|
volumes:
|
||||||
|
- ../:/workspaces/advent22:cached
|
||||||
|
command: sh -c "while sleep 1 & wait $!; do :; done"
|
||||||
|
|
||||||
|
ui:
|
||||||
|
image: mcr.microsoft.com/devcontainers/javascript-node:4-24-trixie
|
||||||
|
volumes:
|
||||||
|
- ../:/workspaces/advent22:cached
|
||||||
|
command: sh -c "while sleep 1 & wait $!; do :; done"
|
||||||
|
|
@ -4,7 +4,10 @@
|
||||||
"name": "Advent22 API",
|
"name": "Advent22 API",
|
||||||
|
|
||||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||||
"image": "mcr.microsoft.com/devcontainers/python:3-3.14-trixie",
|
"dockerComposeFile": "../../.devcontainer/docker_compose.yml",
|
||||||
|
"service": "api",
|
||||||
|
"workspaceFolder": "/workspaces/advent22/api",
|
||||||
|
"runServices": ["api"],
|
||||||
|
|
||||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||||
"features": {
|
"features": {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from .core.settings import SETTINGS
|
from .core.settings import SETTINGS
|
||||||
|
|
@ -33,15 +32,3 @@ if SETTINGS.production_mode:
|
||||||
),
|
),
|
||||||
name="frontend",
|
name="frontend",
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
|
||||||
# Allow CORS in debug mode
|
|
||||||
app.add_middleware(
|
|
||||||
# HACK: suppress while unresolved https://github.com/astral-sh/ty/issues/1635
|
|
||||||
CORSMiddleware, # ty: ignore[invalid-argument-type]
|
|
||||||
allow_credentials=True,
|
|
||||||
allow_origins=["*"],
|
|
||||||
allow_methods=["*"],
|
|
||||||
allow_headers=["*"],
|
|
||||||
expose_headers=["*"],
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@
|
||||||
"name": "Advent22 UI",
|
"name": "Advent22 UI",
|
||||||
|
|
||||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||||
"image": "mcr.microsoft.com/devcontainers/javascript-node:4-24-trixie",
|
"dockerComposeFile": "../../.devcontainer/docker_compose.yml",
|
||||||
|
"service": "ui",
|
||||||
|
"workspaceFolder": "/workspaces/advent22/ui",
|
||||||
|
"runServices": ["ui"],
|
||||||
|
|
||||||
// Features to add to the dev container. More info: https://containers.dev/features.
|
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||||
"features": {
|
"features": {
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,9 @@ interface Params {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class API {
|
export class API {
|
||||||
private static get api_baseurl(): string {
|
|
||||||
// in production mode, return "proto://hostname/api"
|
|
||||||
if (import.meta.env.PROD) {
|
|
||||||
return `${window.location.protocol}//${window.location.host}/api`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// in development mode, return "proto://hostname:8000/api"
|
|
||||||
return `${window.location.protocol}//${window.location.hostname}:8000/api`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly axios = axios.create({
|
private static readonly axios = axios.create({
|
||||||
timeout: 10e3,
|
timeout: 15e3,
|
||||||
baseURL: this.api_baseurl,
|
baseURL: "/api",
|
||||||
});
|
});
|
||||||
|
|
||||||
private static readonly creds_key = "advent22/credentials";
|
private static readonly creds_key = "advent22/credentials";
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,24 @@ vueDevTools(),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
"@": fileURLToPath(new URL("./src", import.meta.url)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
build: {
|
build: {
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://api:8000',
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue