From 48730aa9af67820f2cd54a52ba88f4bd30b5cecd Mon Sep 17 00:00:00 2001 From: Hydroxycarbamide Date: Sun, 20 Oct 2024 16:55:57 +0200 Subject: [PATCH 1/3] Move static files around + add Dockerfile + add docker-compose.yml --- Dockerfile | 11 +++++ {fonts => assets/fonts}/Ubuntu-Regular.ttf | Bin bike.gif => assets/img/bike.gif | Bin cat.gif => assets/img/cat.gif | Bin clouds.gif => assets/img/clouds.gif | Bin plane.gif => assets/img/plane.gif | Bin rest.webp => assets/img/rest.webp | Bin vapor.gif => assets/img/vapor.gif | Bin vaporwave.gif => assets/img/vaporwave.gif | Bin waves.gif => assets/img/waves.gif | Bin bun.lockb | Bin 2758 -> 3151 bytes docker-compose.yml | 9 ++++ index.ts | 48 --------------------- package.json | 11 +++-- index.html => src/index.html | 0 src/index.ts | 39 +++++++++++++++++ style.css => src/style.css | 0 17 files changed, 66 insertions(+), 52 deletions(-) create mode 100644 Dockerfile rename {fonts => assets/fonts}/Ubuntu-Regular.ttf (100%) rename bike.gif => assets/img/bike.gif (100%) rename cat.gif => assets/img/cat.gif (100%) rename clouds.gif => assets/img/clouds.gif (100%) rename plane.gif => assets/img/plane.gif (100%) rename rest.webp => assets/img/rest.webp (100%) rename vapor.gif => assets/img/vapor.gif (100%) rename vaporwave.gif => assets/img/vaporwave.gif (100%) rename waves.gif => assets/img/waves.gif (100%) create mode 100644 docker-compose.yml delete mode 100644 index.ts rename index.html => src/index.html (100%) create mode 100644 src/index.ts rename style.css => src/style.css (100%) 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 5c52b96b82ff5efd282f03ab72175866b93a888c..812ea43fd944995ac39b96466c2832cb80afb51b 100755 GIT binary patch delta 1108 zcmX>mdR}6Jp62zoeTOGTetc%QT}t|3s^NBV30ASZlRxG~q%ewYy1Tz&KQ{vyuulw^ zkIH6;a3CZn14Dx_kO`s_fHY8L!%`s41Ej;z#DQuUxPaobSRG8~zuWIt{U-fvhtO-K ziTY8!YFlkBCmxXCn6KKPqurXCH1Rj8i4V1bs#tiLfE*BJ0b<6< zxlH<;2;N+#ib$Y7Muva<|G+d*4HU3={Is?zUu?uDoa_2Db$3(yfj;gAnd*HC{RUny z`L3GXn!IQc%jVN__V2&)Kj+1jElcc_)-6tPUGN~;(f-7l+Ft^Ulk=FxeKwvv{QOF0 zf_>?+3T;QGV-x&$1#P@yZ{C%fk=P?L>rTm%LuMC>>+M#TWGDt29A%t%xY(|LMy3g~ z-89zn!YJ)oNUmd^+{og?$T(S!MSSvIW(OW5Db~rFEI!CS0fhhzu(X*AUCW5yt+69A zpCjtV`M0|cugRUW!z^#I){V7l>lPOFHp>dVHbyH(oBdGet4^96o^#{OqFsW0m2 zz5Da)YR1WptW}(#@B;ysi4UzOSFnDY{D8@jYXdZO++d$v!DeF!l>YZ00zgVZaRGEC zIQWtI92_7X1A_v`WHojrH3$cxlo==hvJIp?0ID6uR6z^OKQ5vMl~#9a`#0QE^L cg3U`V$}A|+*VRXGbWQcl^o&7<0n^0{06nKMU;qFB delta 825 zcmX>vaZGfAo~BKP6~lpjQ;cTo{}5yCP_erNl<<`kmg1bpT+86I{)2%x9T_PXFG&mD^0v0!NHkt zbL>^%tlbkogs=jYGl)+7s6N?%kwdT?$Z-T}28qf5F%wjRamVDJjP^`#7$#dW*)gdy zPTs|6Hi?l1sE1|p2PPIq=E;AVR42b;;sUcOB7s^N8UFGAV+7F%z!Jo^p!fguRM*4% z1ukY6s<&+KIhVWO<22T(4_u#5khzlC+X$1Ls>z1L5l;nkVuE#;La?^c)|J$Luv(LY{CHtbN|k;^CgrsYG~)9an@ zpB8kks9kpcX=t6<@AaPVHTJAN9x`3&Y`CcklIxf!ce3~}GEA;x5uf~)#Q_+QaEG%_ zHe~S;L^z%yFyl3=blAj?VvKAPKMG?In+4f48M!t;` zn*mko$1%B#!&sZeHl@#L*sZp;>XMw9<>6;5X2mY#fvOKox>+YA73+TNl7 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 From 673c344ff43086a665726edd56009edf7432eee7 Mon Sep 17 00:00:00 2001 From: Hydroxycarbamide Date: Sun, 20 Oct 2024 17:05:36 +0200 Subject: [PATCH 2/3] Update readme.md --- README.md | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3c222e7..68cc221 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,27 @@ -# startpage -My startpage, edited from github.com/kencx +
+ +

Startpage

+
-# How to use? +# Getting Started -1. git clone this repo -2. copy the path to the index.html file -3. set the path as your default startpage in your desired browser +## Using bun.sh -# Customization +``` +bun start +``` -### Image(s) -i have included a few vaporwave/retro styled gifs in this repo, you can edit it on the line 22 in the index.html the ```src="clouds.gif"``` to something like ```src="plane.gif"``` or your own image/gif +## Using docker-compose -### URLs -you can edit all of the URLs to your desired, starting on line **44** in ```index.html``` -
**Example:**
-**line 45:** ```
  • github
  • ```
    can be changed to
    **line 45:** ```
  • your url
  • ``` +``` +docker-compose up --build +``` -### Categories +# Customize -i think you get it, starting on line **44** you can change the names of the categories etc. etc. i believe you're not dumb and understand +Everything is static, just modify the content as you want in `src/` or `assets`. -# Screenshot -![image](https://user-images.githubusercontent.com/76164598/170824479-5918fe82-18df-4549-8b20-c2b1595a27d0.png) +# Contributors + +- [Siklos/Hydroxycarbamide](https://git.siklos-chaneru.dev/Siklos) +- [Woox](https://github.com/nwvh) From 09bc9c6b42d61ac9d29300ead081af955765c165 Mon Sep 17 00:00:00 2001 From: Hydroxycarbamide Date: Sun, 20 Oct 2024 17:39:24 +0200 Subject: [PATCH 3/3] Fix hostname binding and add healthcheck to docker --- Dockerfile | 8 +++++--- docker-compose.yml | 4 +--- package.json | 4 ++-- src/index.ts | 3 +-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8f9fb29..8d5a5b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ - FROM oven/bun:alpine +ENV HOSTNAME localhost + WORKDIR /startpage COPY assets ./assets COPY src ./src +COPY package.json ./ -EXPOSE 8080/tcp +HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD wget --spider -q http://0.0.0.0/healthcheck || exit 1 -ENTRYPOINT [ "bun", "run", "./src/index.ts" ] +ENTRYPOINT [ "bun", "start" ] diff --git a/docker-compose.yml b/docker-compose.yml index 8172c59..e31e179 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,4 @@ services: build: . restart: unless-stopped ports: - - "8080:8080" - environment: - PORT: 8080 + - "8080:80" diff --git a/package.json b/package.json index 1a6ad5b..ef1b5ed 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "startpage", "module": "./src/index.ts", "type": "module", - "script": { - "start": "bun run index.ts" + "scripts": { + "start": "bun run ./src/index.ts" }, "devDependencies": { "bun-types": "^1.1.31" diff --git a/src/index.ts b/src/index.ts index f9c51c0..37cf779 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,9 +16,8 @@ const fetch = (req: Request) => { Bun.serve({ port: Bun.env.PORT || 80, - hostname: Bun.env.HOSTNAME || "localhost", static: { - "/api/healthcheck": new Response("All good!"), + "/healthcheck": new Response("All good!"), "/": new Response(await Bun.file("./src/index.html").bytes(), { headers: { "Content-Type": "text/html",