diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f9fb29 --- /dev/null +++ b/Dockerfile @@ -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" ] diff --git a/fonts/Ubuntu-Regular.ttf b/assets/fonts/Ubuntu-Regular.ttf similarity index 100% rename from fonts/Ubuntu-Regular.ttf rename to assets/fonts/Ubuntu-Regular.ttf diff --git a/bike.gif b/assets/img/bike.gif similarity index 100% rename from bike.gif rename to assets/img/bike.gif diff --git a/cat.gif b/assets/img/cat.gif similarity index 100% rename from cat.gif rename to assets/img/cat.gif diff --git a/clouds.gif b/assets/img/clouds.gif similarity index 100% rename from clouds.gif rename to assets/img/clouds.gif diff --git a/plane.gif b/assets/img/plane.gif similarity index 100% rename from plane.gif rename to assets/img/plane.gif diff --git a/rest.webp b/assets/img/rest.webp similarity index 100% rename from rest.webp rename to assets/img/rest.webp diff --git a/vapor.gif b/assets/img/vapor.gif similarity index 100% rename from vapor.gif rename to assets/img/vapor.gif diff --git a/vaporwave.gif b/assets/img/vaporwave.gif similarity index 100% rename from vaporwave.gif rename to assets/img/vaporwave.gif diff --git a/waves.gif b/assets/img/waves.gif similarity index 100% rename from waves.gif rename to assets/img/waves.gif diff --git a/bun.lockb b/bun.lockb index 5c52b96..812ea43 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8172c59 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + app: + image: startpage + build: . + restart: unless-stopped + ports: + - "8080:8080" + environment: + PORT: 8080 diff --git a/index.ts b/index.ts deleted file mode 100644 index 20e2cc4..0000000 --- a/index.ts +++ /dev/null @@ -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 -}); - diff --git a/package.json b/package.json index 96710f6..1a6ad5b 100644 --- a/package.json +++ b/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" } -} \ No newline at end of file +} diff --git a/index.html b/src/index.html similarity index 100% rename from index.html rename to src/index.html diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..f9c51c0 --- /dev/null +++ b/src/index.ts @@ -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, +}); diff --git a/style.css b/src/style.css similarity index 100% rename from style.css rename to src/style.css