Skip to content

Commit

Permalink
Update README and github workflow for Bun
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Evans <[email protected]>
  • Loading branch information
mrbrianevans committed Sep 23, 2023
1 parent 242b28c commit d108083
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 48 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/build-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: pnpm/[email protected]
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
30 changes: 15 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 21 additions & 21 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit d108083

Please sign in to comment.