Move static files around + add Dockerfile + add docker-compose.yml

This commit is contained in:
Hydroxycarbamide 2024-10-20 16:55:57 +02:00
parent 5405630490
commit 48730aa9af
17 changed files with 66 additions and 52 deletions

11
Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM oven/bun:alpine
WORKDIR /startpage
COPY assets ./assets
COPY src ./src
EXPOSE 8080/tcp
ENTRYPOINT [ "bun", "run", "./src/index.ts" ]

View file

Before

Width:  |  Height:  |  Size: 340 KiB

After

Width:  |  Height:  |  Size: 340 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 562 KiB

After

Width:  |  Height:  |  Size: 562 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.4 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3 MiB

After

Width:  |  Height:  |  Size: 3 MiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 169 KiB

After

Width:  |  Height:  |  Size: 169 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.8 MiB

After

Width:  |  Height:  |  Size: 1.8 MiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.6 MiB

After

Width:  |  Height:  |  Size: 4.6 MiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1,005 KiB

After

Width:  |  Height:  |  Size: 1,005 KiB

Before After
Before After

BIN
bun.lockb

Binary file not shown.

9
docker-compose.yml Normal file
View file

@ -0,0 +1,9 @@
services:
app:
image: startpage
build: .
restart: unless-stopped
ports:
- "8080:8080"
environment:
PORT: 8080

View file

@ -1,48 +0,0 @@
console.log("Hello World!");
const fetch = (req: Request) => {
const url = new URL(req.url);
const path = url.pathname;
if (path === "/") {
return new Response(Bun.file("./index.html"), {
headers: {
"Content-Type": "text/html"
}
});
} else if (path === "/style.css") {
return new Response(Bun.file("./style.css"), {
headers: {
"Content-Type": "text/css"
}
});
} else if (path === "/cat.gif") {
return new Response(Bun.file("./cat.gif"), {
headers: {
"Content-Type": "image/gif"
}
});
} else if (path === "/favicon.ico") {
return new Response(Bun.file("./favicon.ico"), {
headers: {
"Content-Type": "image/x-icon"
}
})
} else if (path.startsWith('/fonts/')) {
const fontPath = path.slice('/fonts/'.length);
return new Response(Bun.file(`./fonts/${fontPath}`), {
headers: {
"Content-Type": "application/octet-stream"
}
})
}
return new Response("404!");
}
Bun.serve({
port: Bun.env.PORT || 80,
hostname: Bun.env.HOSTNAME || "localhost",
fetch
});

View file

@ -1,11 +1,14 @@
{
"name": "startpage",
"module": "index.ts",
"module": "./src/index.ts",
"type": "module",
"script": {
"start": "bun run index.ts"
},
"devDependencies": {
"bun-types": "latest"
"bun-types": "^1.1.31"
},
"peerDependencies": {
"typescript": "^5.0.0"
"typescript": "^5.6.3"
}
}

39
src/index.ts Normal file
View file

@ -0,0 +1,39 @@
const fetch = (req: Request) => {
const url = new URL(req.url);
const path = url.pathname;
if (path.startsWith('/fonts/')) {
const fontPath = path.slice('/fonts/'.length);
return new Response(Bun.file(`./assets/fonts/${fontPath}`), {
headers: {
"Content-Type": "application/octet-stream"
}
})
}
return new Response("404!");
};
Bun.serve({
port: Bun.env.PORT || 80,
hostname: Bun.env.HOSTNAME || "localhost",
static: {
"/api/healthcheck": new Response("All good!"),
"/": new Response(await Bun.file("./src/index.html").bytes(), {
headers: {
"Content-Type": "text/html",
},
}),
"/style.css": new Response(await Bun.file("./src/style.css").bytes(), {
headers: {
"Content-Type": "text/css"
},
}),
"/cat.gif": new Response(await Bun.file("./assets/img/cat.gif").bytes(), {
headers: {
"Content-Type": "image/gif",
},
}),
},
fetch,
});