🧱 update CI workflow and remove alpinejs frontend files
Some checks failed
CI / Lint (push) Successful in 21s
CI / Helm Lint (push) Successful in 5s
CI / Build (push) Failing after 43s
CI / Test (push) Has been skipped

This commit is contained in:
Christian van Dijk
2026-02-23 15:46:31 +01:00
parent a545ef5af4
commit a6daab7961
17 changed files with 78 additions and 53 deletions

View File

@@ -9,8 +9,8 @@ ENV PORT=${PORT}
WORKDIR /app
# Copy the frontend files
# Since the Dockerfile is in the root and files are in alpinejs/, we copy from there
COPY alpinejs/ .
# Since the Dockerfile is in the root and files are in ./, we copy from there
COPY . .
# Ensure the deno user owns the directory so it can write public/config.js
RUN chown -R deno:deno /app

View File

@@ -3,6 +3,7 @@
"start": "deno run --allow-net --allow-read --allow-write --allow-env --allow-run --watch main.ts"
},
"imports": {
"@dx/alpine-server": "jsr:@dx/alpine-server"
"@dx/alpine-server": "jsr:@dx/alpine-server",
"@oak/oak": "jsr:@oak/oak@^17.2.0"
}
}

View File

@@ -114,7 +114,8 @@
},
"workspace": {
"dependencies": [
"jsr:@dx/alpine-server@*"
"jsr:@dx/alpine-server@*",
"jsr:@oak/oak@^17.2.0"
]
}
}

View File

@@ -1,23 +1,24 @@
import { AlpineApp } from '@dx/alpine-server';
import { Router } from 'jsr:@oak/oak';
import { AlpineApp } from "@dx/alpine-server";
import { Context, Router } from "@oak/oak";
let config = {
api_url: Deno.env.get('API_URL') || 'http://localhost:8080',
port: parseInt(Deno.env.get('PORT') || '8090')
api_url: Deno.env.get("API_URL") || "http://localhost:8080",
port: parseInt(Deno.env.get("PORT") || "8090"),
};
try {
const configFile = await Deno.readTextFile('./config.json');
const configFile = await Deno.readTextFile("./config.json");
const fileConfig = JSON.parse(configFile);
config = { ...config, ...fileConfig };
} catch (e) {
console.warn('Could not read config.json, using defaults', e.message);
// deno-lint-ignore no-explicit-any
} catch (e: any) {
console.warn("Could not read config.json, using defaults", e.message);
}
const app = new AlpineApp({
app: {
dev: true,
staticFilesPath: './public',
staticFilesPath: "./public",
},
oak: {
listenOptions: { port: config.port },
@@ -25,17 +26,17 @@ const app = new AlpineApp({
});
const healthRouter = new Router();
healthRouter.get('/health', (ctx) => {
ctx.response.body = { status: 'ok' };
healthRouter.get("/health", (ctx: Context) => {
ctx.response.body = { status: "ok" };
ctx.response.status = 200;
});
app.append(healthRouter);
app.use(async (ctx, next) => {
app.use(async (ctx: Context, next: () => Promise<unknown>) => {
await next();
const contentType = ctx.response.headers.get('content-type') || '';
if (contentType.includes('text/html')) {
let csp = ctx.response.headers.get('Content-Security-Policy');
const contentType = ctx.response.headers.get("content-type") || "";
if (contentType.includes("text/html")) {
let csp = ctx.response.headers.get("Content-Security-Policy");
if (!csp) {
// securityHeaders might not have set it yet if it runs after us in the call stack
// but in run(), securityHeaders is app.use()ed BEFORE user middlewares.
@@ -52,10 +53,13 @@ app.use(async (ctx, next) => {
"font-src 'self'",
"connect-src 'self'",
"media-src 'self'",
].join('; ');
].join("; ");
}
const updatedCsp = csp.replace("connect-src 'self'", `connect-src 'self' ${config.api_url} ws:`);
ctx.response.headers.set('Content-Security-Policy', updatedCsp);
const updatedCsp = csp.replace(
"connect-src 'self'",
`connect-src 'self' ${config.api_url} ws:`,
);
ctx.response.headers.set("Content-Security-Policy", updatedCsp);
}
});
@@ -63,6 +67,9 @@ console.log(`URL: http://localhost:${config.port}`);
console.log(`API: ${config.api_url}`);
// Create config.js file in public directory
await Deno.writeTextFile('./public/config.js', `window.APP_CONFIG = ${JSON.stringify(config)};`);
await Deno.writeTextFile(
"./public/config.js",
`window.APP_CONFIG = ${JSON.stringify(config)};`,
);
await app.run();

View File

Before

Width:  |  Height:  |  Size: 699 B

After

Width:  |  Height:  |  Size: 699 B