Move static files around + add Dockerfile + add docker-compose.yml
11
Dockerfile
Normal 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" ]
|
Before Width: | Height: | Size: 340 KiB After Width: | Height: | Size: 340 KiB |
Before Width: | Height: | Size: 562 KiB After Width: | Height: | Size: 562 KiB |
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.4 MiB |
Before Width: | Height: | Size: 3 MiB After Width: | Height: | Size: 3 MiB |
Before Width: | Height: | Size: 169 KiB After Width: | Height: | Size: 169 KiB |
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 1.8 MiB |
Before Width: | Height: | Size: 4.6 MiB After Width: | Height: | Size: 4.6 MiB |
Before Width: | Height: | Size: 1,005 KiB After Width: | Height: | Size: 1,005 KiB |
BIN
bun.lockb
9
docker-compose.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
services:
|
||||
app:
|
||||
image: startpage
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8080:8080"
|
||||
environment:
|
||||
PORT: 8080
|
48
index.ts
|
@ -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
|
||||
});
|
||||
|
11
package.json
|
@ -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
|
@ -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,
|
||||
});
|