🧱 update CI workflow and remove alpinejs frontend files
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
3
frontend/alpinejs/deno.lock → frontend/deno.lock
generated
3
frontend/alpinejs/deno.lock → frontend/deno.lock
generated
@@ -114,7 +114,8 @@
|
||||
},
|
||||
"workspace": {
|
||||
"dependencies": [
|
||||
"jsr:@dx/alpine-server@*"
|
||||
"jsr:@dx/alpine-server@*",
|
||||
"jsr:@oak/oak@^17.2.0"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
Before Width: | Height: | Size: 699 B After Width: | Height: | Size: 699 B |
Reference in New Issue
Block a user