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 0000000..5013769 Binary files /dev/null and b/server/bun.lockb differ diff --git a/server/package.json b/server/package.json index 67b0b60..d3a6e4b 100644 --- a/server/package.json +++ b/server/package.json @@ -14,7 +14,7 @@ "@types/node": "^18.11.9", "bun-types": "^1.0.3", "mitata": "^0.1.6", - "typescript": "^4.8.4" + "typescript": "latest" }, "dependencies": { "@streamparser/json-node": "^0.0.15", diff --git a/server/tsconfig.json b/server/tsconfig.json index 752e618..59732a5 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -1,26 +1,26 @@ { - "compileOnSave": true, "compilerOptions": { - "skipLibCheck": true, - "outDir": "dist", - "target": "ES2022", - "moduleResolution": "node", - "strictNullChecks": true, - "module": "ES2022", - "allowSyntheticDefaultImports": true, - "lib": [ - "ESNext" - ], - "inlineSourceMap": true, - "inlineSources": true, "types": [ "bun-types" - ] - }, - "include": [ - "src" - ], - "exclude": [ - "../node_modules" - ] + ], + "lib": [ + "esnext" + ], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "noEmit": true, + "allowImportingTsExtensions": true, + "moduleDetection": "force", + "allowJs": true, + "esModuleInterop": true, + // best practices + "strict": false, + // TODO: put to true, fix errors + "forceConsistentCasingInFileNames": true, + "skipLibCheck": true, + "composite": true, + "downlevelIteration": true, + "allowSyntheticDefaultImports": true + } }