Skip to content

Instantly share code, notes, and snippets.

@minskmaz
Forked from studiokeywi/Dockerfile
Created August 8, 2023 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minskmaz/40fc211070ae1b9fe322a733305192e3 to your computer and use it in GitHub Desktop.
Save minskmaz/40fc211070ae1b9fe322a733305192e3 to your computer and use it in GitHub Desktop.
flygun
FROM node:latest
WORKDIR /app
COPY ./index.js ./
COPY ./package*.json ./
RUN npm ci
EXPOSE 8080
CMD ["npm", "start"]
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'));
{
"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