From 6599d49761065b126e915fab28e8343dbb9a90c9 Mon Sep 17 00:00:00 2001 From: Brian Evans Date: Sat, 23 Sep 2023 22:08:44 +0100 Subject: [PATCH] Update README and github workflow for Bun Signed-off-by: Brian Evans --- .github/workflows/build-server.yaml | 14 ++-------- readme.md | 30 ++++++++++---------- server/bun.lockb | Bin 0 -> 21112 bytes server/package.json | 2 +- server/tsconfig.json | 42 ++++++++++++++-------------- 5 files changed, 40 insertions(+), 48 deletions(-) create mode 100644 server/bun.lockb diff --git a/.github/workflows/build-server.yaml b/.github/workflows/build-server.yaml index f770307..cad85a6 100644 --- a/.github/workflows/build-server.yaml +++ b/.github/workflows/build-server.yaml @@ -11,18 +11,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2.2.2 - with: - version: 7 - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: "19" - cache: pnpm - cache-dependency-path: 'server/pnpm-lock.yaml' + - uses: oven-sh/setup-bun@v1 - name: Install dependencies - run: pnpm install + run: bun install --frozen-lockfile working-directory: server - name: Build server typescript - run: pnpm run build + run: bun run build working-directory: server diff --git a/readme.md b/readme.md index 9bf37b9..d02e6ca 100644 --- a/readme.md +++ b/readme.md @@ -8,34 +8,34 @@ Companies House offers a streaming API, which sends events over a HTTPS connecti ## Technology -- [NodeJS](https://nodejs.org) server with [express](https://www.npmjs.com/package/express) written - in [TypeScript](https://www.typescriptlang.org/) run in [Docker](https://www.docker.com/) container deployed on [Digital Ocean](https://www.digitalocean.com/). +- server written in [TypeScript](https://www.typescriptlang.org/) with [Elysia](https://elysiajs.com) framework + and [Bun](https://bun.sh) + runtime run + in [Docker](https://www.docker.com/) container deployed on [Digital Ocean](https://www.digitalocean.com/). - [Redis Streams](https://redis.io/docs/data-types/streams/). - [WebSockets](https://javascript.info/websocket) for client-server communication. -- Frontend client using Typescript and [Vite](https://vitejs.dev/) (no frameworks, 10kb bundle). +- Frontend client written in Typescript and built with [Vite](https://vitejs.dev/) (no frameworks, 10kb bundle). +- Served by [Caddy](https://caddyserver.com/) ## How it works A [Docker compose](https://docs.docker.com/compose/) application with 3 main components for the backend: -1. A NodeJS container to listen on the Companies House streaming API and publish events to Redis ( +1. A container to listen on the Companies House streaming API and publish events to Redis ( see [streamToRedis.ts](server/src/redis/streamToRedis.ts)). -2. A Redis instance, mostly for facilitating Pub/Sub communication of events using Streams, and also for storing most recent timepoint +2. A Redis instance, mostly for facilitating Pub/Sub communication of events using Streams, and also for storing most + recent timepoint to avoid missing any events. -3. A NodeJS container which reads events from the Redis Stream and serves them as a WebSocket endpoint +3. A container which reads events from the Redis Stream and serves them as a WebSocket endpoint on `/events`, where each event is sent as a WebSocket message. -The frontend is "pure" in that it doesn't use a framework like React, which keeps the JS bundle really tiny and high performance. +The frontend is "pure" in that it doesn't use a framework like React, which keeps the JS bundle really tiny and high +performance. The animations are done in CSS using [SASS](https://sass-lang.com/). -It is built with Vite in a Docker container, and served with [Caddy](https://caddyserver.com/) (which is also a gateway -to the backend endpoints and WebSocket). To start up the whole application, clone the repository and run `docker compose up -d --build` in the root. You will need an env file named `.api.env`containing streaming API key(s). -To run any files without Docker, build the project by installing dependencies compiling -TypeScript (`pnpm i && pnpm build` in `/server` and `/client`). -[PNPM](https://pnpm.io/) is used as the package manager, but [NPM](https://docs.npmjs.com/cli/v8) will also work (but it -won't recognise the lock files). +To run any files without Docker, install Bun (`bun install` in `/server` and `/client`). ## Make your own @@ -62,14 +62,14 @@ get(options, (res) => { }).end() ``` -For a more complete working example of listening on a stream in NodeJS, +For a more complete working example of listening on a stream in Javascript, see [server/src/streams/splitStream.ts](server/src/streams/splitStream.ts) and then [server/src/redis/streamToRedis.ts](server/src/redis/streamToRedis.ts). To test the streaming API from the command line with CURL, you can use the cmdline utility (after compiling): ```bash -curl --user APIKEY: -s https://stream.companieshouse.gov.uk/filings | node dist/streams/streamCmdLine.js +curl --user APIKEY: -s https://stream.companieshouse.gov.uk/filings | bun src/streams/streamCmdLine.ts ``` # Questions? diff --git a/server/bun.lockb b/server/bun.lockb new file mode 100644 index 0000000000000000000000000000000000000000..5013769992a28ac4c4831896bb9e13e21aeac6c1 GIT binary patch literal 21112 zcmeHv2{@G9`~P6HC`(C1ib`dfu`6prixw?tQDiU}#*Ai$(59ljC@oqgZLjvCP1>~Y zilnzvTBTI9h+cm8{mdLa_4cCg_r3nt|9Abmub$5HoO3>(bD#UH&w1R_UEefHEHVw? z2~4?yXuW_aff8ISzA!L6n8)X`f`y_8j)WC$rX=Mtg|g51}%I+aPQM;aUhW{}NezEQinMi6xA- z3exzmpuQTU&ywYf7SENW7$Q6qj+-R;q0u=~|3J&Iq7z`el%k5)r#n5ZbV8Fll zLcpPZkKv&mgkymh!(k92&qUA_^KtpHVjhRVh=WM1|6~X;o&zD`he0JeLFgq*cay~j z3Wec3E`wnS&&WF(_^_UmP?0byB$QDLWXNL=@mQY=PzkiNxh!7qV2n0rMESH?>}6U zVSX>ByPxIBFL!Ny)@=2AJa4h%5H)M=m7Ah->yLqZGK>}0Xjo`^4jQz|$*5HQ^^Te@>T$v63@v(1XN?`J zJYl8X$zliZmEm`%UaNUsC-}7U^reKf$30a~#*Hf~+LAYRmr5tg3a{W6ZsBY8XXtw# zw(4~M${WRT{d=CY$+`7BV23zsp8lVve!cwkUu3&ztF{00_{EZz+gt|7ze_vk?zXsh z-07qQ@2I-bUEQk3j$Y5Gds}n4n|wFB>-ffww z&yt?mj5o9PV{?SyHQ)xuE@eNg|F7al z0v;x13XkPBw+%@7^WesoR(^AI$2UdmnVSQqt4$TpQe+PIM zz~l3;*pT2YpwXNGk7bfLyl+ZKUJ>B2{n7q-HCG6JkF5OW)|>DXdC%tb9Eqi zXBaSEfG4&iAt~pdLV{lb_<^$WN!&kS=2k$>bf8_kt^4$TC;~#Ywc+?;BcZCbr@a71?p9DPF zKVjQ9R|kSuf%iR}KkymxzuJG@08i!*#Q&=OW&qw@R)2v1a{Y?|-|xS`_W*;V{m^b` z17a7{r7BzdC-e%kc2dj_>#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