├── .gitignore
├── Dockerfile
├── LICENSE
├── README.md
├── bun.lockb
├── index.js
├── lib
└── test.html
├── package.json
├── public
├── stats.html
└── style.css
└── serve-bun.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | bunsAndGuns.code-workspace
3 | .vscode
4 | .env
5 | radata
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM oven/bun
2 |
3 | WORKDIR /app
4 | COPY package.json package.json
5 | COPY bun.lockb bun.lockb
6 | RUN bun install
7 | COPY . .
8 | EXPOSE 3000
9 |
10 | ENTRYPOINT ["bun", "index.js"]
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 James
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # gundb-relay
2 | Simple gun db relay running on Bun.js
3 |
4 | Connect and test with this public peer/relay: https://plankton-app-6qfp3.ondigitalocean.app/
5 |
--------------------------------------------------------------------------------
/bun.lockb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jamesgibson14/bunsAndGuns/a5e2dc6e22195c4bde6d19b763cc0c025b46fa74/bun.lockb
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import Bun from 'bun'
2 | import Gun from 'gun/gun'
3 | import SEA from 'gun/sea'
4 | globalThis.GUN = Gun
5 | // This is mostly copied from 'gun/lib/server.js'
6 | var u;
7 | Gun.on('opt', function(root){
8 | if(u === root.opt.super){ root.opt.super = true }
9 | if(u === root.opt.faith){ root.opt.faith = true } // HNPERF: This should probably be off, but we're testing performance improvements, please audit.
10 | root.opt.log = root.opt.log || Gun.log;
11 | this.to.next(root);
12 | })
13 | require('gun/lib/store.js');
14 | require('gun/lib/rfs.js');
15 | require('gun/lib/rs3.js');
16 | // replacing wire.js with this file
17 | // require('./wire');
18 |
19 | require('gun/sea.js')
20 | require('gun/axe.js')
21 | require('gun/lib/stats.js');
22 | // multicast doesn't work with Bun because dgram is not supported yet: https://bun.sh/docs/runtime/nodejs-apis
23 | // require('gun/lib/multicast.js');
24 |
25 | //
26 | import httpConfig from './serve-bun.js'
27 | const server = Bun.serve( httpConfig )
28 |
29 | const env = process.env
30 | const VALID_KEY = env.VALID_KEY
31 | const USE_RADISK = env.DISABLE_RADISK !== 'true'
32 | const USE_AXE = env.DISABLE_AXE !== 'true'
33 | const gun = globalThis.gunInstance = Gun({
34 | web: server,
35 | axe: USE_AXE,
36 | localStorage: false,
37 | radisk: USE_RADISK,
38 | peers: env?.PEERS?.split(',') || [],
39 | validKey: VALID_KEY,
40 | multicast: false,
41 | pack: 599000000 * 0.3,
42 | s: {
43 | key: env.AWS_ACCESS_KEY_ID, // AWS Access Key
44 | secret: env.AWS_SECRET_ACCESS_KEY, // AWS Secret Token
45 | bucket: env.AWS_S3_BUCKET // The bucket you want to save into
46 | }
47 | })
48 | console.log('Running Bun and Gun')
--------------------------------------------------------------------------------
/lib/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |