Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules/
dist/
.astro/
.env
.env.*
.git/
.gitignore
.DS_Store
README.md
Dockerfile
.dockerignore
npm-debug.log*
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM oven/bun:1 AS build

WORKDIR /app

COPY package.json bun.lock ./
RUN bun install --frozen-lockfile

COPY . .
RUN bun run build

FROM oven/bun:1-slim

WORKDIR /app

COPY --from=build /app/dist ./dist
COPY serve.ts ./

CMD ["bun", "run", "serve.ts"]
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: bun run serve.ts
release: echo 'deploy'
5 changes: 5 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"devDependencies": {
"@astrojs/check": "^0.9.9",
"@tailwindcss/postcss": "^4.3.1",
"@types/bun": "^1.3.11",
"@types/mdast": "^4.0.4",
"@types/turndown": "^5.0.6",
"fast-xml-parser": "^5.9.2",
Expand Down
43 changes: 43 additions & 0 deletions serve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { join, resolve } from "node:path";

const DIST = resolve(import.meta.dirname, "dist");
const SOCK = "/var/run/cabotage/cabotage.sock";

async function serveFile(filePath: string): Promise<Response | null> {
const resolved = resolve(filePath);
if (!resolved.startsWith(DIST)) return null;
const file = Bun.file(resolved);
if (await file.exists()) return new Response(file);
return null;
}

Bun.serve({
unix: SOCK,
async fetch(req) {
const url = new URL(req.url);
const pathname = decodeURIComponent(url.pathname);

// Try exact file
let resp = await serveFile(join(DIST, pathname));
if (resp) return resp;

// Try as directory with index.html
resp = await serveFile(join(DIST, pathname, "index.html"));
if (resp) return resp;

// Try with .html extension
resp = await serveFile(join(DIST, pathname + ".html"));
if (resp) return resp;

// 404
const notFound = await serveFile(join(DIST, "404.html"));
if (notFound)
return new Response(notFound.body, {
status: 404,
headers: notFound.headers,
});
return new Response("Not Found", { status: 404 });
},
});

console.log(`Listening on ${SOCK}`);
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"exclude": ["dist", "scripts"],
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react"
"jsxImportSource": "react",
"types": ["bun"]
}
}