Compare commits

..

No commits in common. "005bb31fca9f2145b109539501a4d79e80bfccff" and "d9f4042bd3cb6773a9f6daa4bf3faf4f6b3b5dc4" have entirely different histories.

7 changed files with 32 additions and 40 deletions

View file

@ -1,14 +0,0 @@
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"

View file

@ -24,6 +24,7 @@ COPY ui ./
RUN --mount=type=cache,id=ui,target=/root/.yarn \ RUN --mount=type=cache,id=ui,target=/root/.yarn \
set -ex; \ set -ex; \
\ \
yarn dlx update-browserslist-db@latest; \
yarn build --outDir /opt/advent22/ui; \ yarn build --outDir /opt/advent22/ui; \
# exclude webpack-bundle-analyzer output # exclude webpack-bundle-analyzer output
rm -f /opt/advent22/ui/stats.html; rm -f /opt/advent22/ui/stats.html;

View file

@ -4,10 +4,7 @@
"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
"dockerComposeFile": "../../.devcontainer/docker_compose.yml", "image": "mcr.microsoft.com/devcontainers/python:3-3.14-trixie",
"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": {
@ -59,4 +56,4 @@
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root" // "remoteUser": "root"
} }

View file

@ -1,4 +1,5 @@
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
@ -32,3 +33,15 @@ 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=["*"],
)

View file

@ -4,10 +4,7 @@
"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
"dockerComposeFile": "../../.devcontainer/docker_compose.yml", "image": "mcr.microsoft.com/devcontainers/javascript-node:4-24-trixie",
"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": {
@ -47,7 +44,7 @@
// "postCreateCommand": "yarn install", // "postCreateCommand": "yarn install",
// Use 'postStartCommand' to run commands after the container is started. // Use 'postStartCommand' to run commands after the container is started.
"postStartCommand": "yarn install" "postStartCommand": "yarn dlx update-browserslist-db@latest && yarn install"
// Use 'forwardPorts' to make a list of ports inside the container available locally. // Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [], // "forwardPorts": [],

View file

@ -16,9 +16,19 @@ 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: 15e3, timeout: 10e3,
baseURL: "/api", baseURL: this.api_baseurl,
}); });
private static readonly creds_key = "advent22/credentials"; private static readonly creds_key = "advent22/credentials";

View file

@ -9,8 +9,8 @@ import vueDevTools from "vite-plugin-vue-devtools";
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [
vue(), vue(),
vueDevTools(), vueDevTools(),
analyzer({ analyzer({
analyzerMode: "static", analyzerMode: "static",
}), }),
@ -22,24 +22,12 @@ export default defineConfig({
}, },
}), }),
], ],
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,
},
},
},
}); });