Examples of how to restrict writes and still have public reads with GUN
This is a bit out of sync at the moment. Maybe I'll fix it some day...
Use at your own risk :-)
Clone or download the repo.
cd into directory and run npm install
Open a terminal and start the services
$ npm run sea
This will start 3 servers
- The GUN server at localhost port 8000
- The authenticated site on localhost port 3000
- The unauthenticated site on localhost port 4000
Open your browser at http://localhost:3000
Login with whatever username/password you want. If the user doesn't exist it will be created.
Add some messages
Use the link to open the unathorized site
Everything you write on the authenticated site will be synced to the unathenticated, but not the other way around.
Shut down the services with CTRL + C
in the terminal
Open a terminal and start the services
$ npm start
This will start 3 servers
- The GUN server at localhost port 8000
- The authenticated site on localhost port 3000
- The unauthenticated site on localhost port 4000
Open 2 browsers.
- Visit http://localhost:3000 in one
- Visit http://localhost:4000 in the other
Everything you write on the authenticated site will be synced to the unathenticated, but not the other way around.
If you want to se GUN in action without restrictions stop the running service pressing CTRL + C in the terminal.
Start an unrestricted GUN server.
$ npm run unrestricted
Now your sync will work both ways.
The solutions are based on an answer from stackoverflow, the SEA contact example and of course the GUN Gitter