Created
August 3, 2023 21:11
-
-
Save studiokeywi/63d638ad5aa5f307b7c681af58790152 to your computer and use it in GitHub Desktop.
flygun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:latest | |
WORKDIR /app | |
COPY ./index.js ./ | |
COPY ./package*.json ./ | |
RUN npm ci | |
EXPOSE 8080 | |
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Gun from 'gun'; | |
import cluster from 'node:cluster'; | |
import { createServer } from 'node:http'; | |
const dir = import.meta.dir ?? import.meta.url.replace(/^file:\/{1,}(.+)\/.+?$/, './$1'); | |
const died = 'worker %d died (%s)... creating new worker'; | |
const fork = () => cluster.fork(); | |
const srvListen = port => () => console.log('GUN database running on :%d', port); | |
const wrkListen = ({ process: { pid } }, c, s) => (console.log(died, pid, s || c), fork()); | |
((host, port) => { | |
if (cluster.isPrimary) return fork(), cluster.on('exit', wrkListen); | |
const server = createServer({}, Gun.serve(dir)); | |
const web = server.listen(port, host, srvListen(port)); | |
Gun({ web, peers: {} }); | |
})(process.env.HOST ?? '0.0.0.0', +(process.env.PORT ?? '8080')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.0.1", | |
"scripts": { | |
"start": "node index.js" | |
}, | |
"dependencies": { | |
"gun": "latest" | |
}, | |
"type": "module" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment