mirror of
https://github.com/amark/gun.git
synced 2025-06-07 14:46:44 +00:00
Merge pull request #346 from zwhitchcox/master
add hapi, refactor examples
This commit is contained in:
commit
e60d7acee0
@ -37,7 +37,7 @@
|
|||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
($.model = $('ul li').clone(true)).removeAttribute('class');
|
($.model = $('ul li').clone(true)).removeAttribute('class');
|
||||||
var gun = Gun(location.origin + '/gun');
|
var gun = Gun(location.origin);
|
||||||
var chat = gun.get('example/chat/data');
|
var chat = gun.get('example/chat/data');
|
||||||
chat.map().val(function(msg, field){
|
chat.map().val(function(msg, field){
|
||||||
console.log("msg", field, msg);
|
console.log("msg", field, msg);
|
||||||
|
@ -1,24 +1,13 @@
|
|||||||
console.log("If modules not found, run `npm install` in /example folder!"); // git subtree push -P examples heroku master // OR // git subtree split -P examples master && git push heroku [['HASH']]:master --force
|
console.log("If modules not found, run `npm install` in /example folder!"); // git subtree push -P examples heroku master // OR // git subtree split -P examples master && git push heroku [['HASH']]:master --force
|
||||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8080;
|
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8080;
|
||||||
|
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var http = require('http');
|
var Gun = require('..');
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
var server = http.createServer(app);
|
|
||||||
|
|
||||||
var Gun = require('../');
|
|
||||||
var gun = Gun({
|
|
||||||
file: 'data.json',
|
|
||||||
web: server,
|
|
||||||
s3: {
|
|
||||||
key: '', // AWS Access Key
|
|
||||||
secret: '', // AWS Secret Token
|
|
||||||
bucket: '' // The bucket you want to save into
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(Gun.serve);
|
app.use(Gun.serve);
|
||||||
app.use(express.static(__dirname));
|
app.use(express.static(__dirname));
|
||||||
server.listen(port);
|
|
||||||
|
var server = app.listen(port);
|
||||||
|
Gun({ file: 'data.json', web: server });
|
||||||
|
|
||||||
console.log('Server started on port ' + port + ' with /gun');
|
console.log('Server started on port ' + port + ' with /gun');
|
||||||
|
29
examples/hapi.js
Normal file
29
examples/hapi.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
const Hapi = require('hapi')
|
||||||
|
const Inert = require('inert')
|
||||||
|
const Gun = require('..')
|
||||||
|
|
||||||
|
const server = new Hapi.Server
|
||||||
|
server.connection({ port: 8080 })
|
||||||
|
server.connections.forEach(c => Gun({ web: c.listener, file: 'data.json' }))
|
||||||
|
|
||||||
|
server.register(Inert, () => {});
|
||||||
|
|
||||||
|
server.route({
|
||||||
|
method: 'GET',
|
||||||
|
path: '/gun.js',
|
||||||
|
handler: (request, reply) => reply.file('../gun.js', { confine: false })
|
||||||
|
})
|
||||||
|
|
||||||
|
server.route({
|
||||||
|
method: 'GET',
|
||||||
|
path: '/{param*}',
|
||||||
|
handler: {
|
||||||
|
directory: {
|
||||||
|
path: __dirname,
|
||||||
|
redirectToSlash: true,
|
||||||
|
index: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
server.start()
|
@ -26,7 +26,7 @@
|
|||||||
function clean(text){ return String(text).replace(/\</ig, '<') }
|
function clean(text){ return String(text).replace(/\</ig, '<') }
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
var gun = Gun(location.origin + '/gun');
|
var gun = Gun(location.origin);
|
||||||
var ref = gun.get('example/json/data');
|
var ref = gun.get('example/json/data');
|
||||||
$('#form').onsubmit = function(e){
|
$('#form').onsubmit = function(e){
|
||||||
return ref.path( clean($('#field').value) ).put("value"), false; // add a new field, and cancel the form submit.
|
return ref.path( clean($('#field').value) ).put("value"), false; // add a new field, and cancel the form submit.
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
function clean(text){ return String(text).replace(/\</ig, '<') }
|
function clean(text){ return String(text).replace(/\</ig, '<') }
|
||||||
</script>
|
</script>
|
||||||
<script> // by Forrest Tait! Edited by Mark Nadal.
|
<script> // by Forrest Tait! Edited by Mark Nadal.
|
||||||
var gun = Gun(location.origin + '/gun');
|
var gun = Gun(location.origin);
|
||||||
var todo = gun.get('example/todo/data');
|
var todo = gun.get('example/todo/data');
|
||||||
$("#add").onsubmit = function(){
|
$("#add").onsubmit = function(){
|
||||||
todo.path(Gun.text.random()).put(clean($("#todo").value)); // add the HTML input's value to a random ID in the todo.
|
todo.path(Gun.text.random()).put(clean($("#todo").value)); // add the HTML input's value to a random ID in the todo.
|
||||||
|
2
gun.min.js
vendored
2
gun.min.js
vendored
File diff suppressed because one or more lines are too long
@ -54,10 +54,12 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"express": "~>4.13.4",
|
"express": "~>4.13.4",
|
||||||
|
"hapi": "^16.1.0",
|
||||||
|
"inert": "^4.1.0",
|
||||||
|
"ip": "^1.1.4",
|
||||||
"mocha": "~>1.9.0",
|
"mocha": "~>1.9.0",
|
||||||
"uglify-js": "~>2.2.0",
|
|
||||||
"panic-manager": "^1.2.0",
|
"panic-manager": "^1.2.0",
|
||||||
"panic-server": "^1.1.0",
|
"panic-server": "^1.1.0",
|
||||||
"ip": "^1.1.4"
|
"uglify-js": "~>2.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
var Gun = require('./root');
|
var Gun = require('./root');
|
||||||
Gun.chain.get = function(key, cb, as){
|
Gun.chain.get = function(key, cb, as){
|
||||||
//if(!as || !as.path){ var back = this._.root; } // TODO: CHANGING API! Remove this line!
|
|
||||||
if(typeof key === 'string'){
|
if(typeof key === 'string'){
|
||||||
var gun, back = back || this, cat = back._;
|
var gun, back = this, cat = back._;
|
||||||
var next = cat.next || empty, tmp;
|
var next = cat.next || empty, tmp;
|
||||||
if(!(gun = next[key])){
|
if(!(gun = next[key])){
|
||||||
gun = cache(key, back);
|
gun = cache(key, back);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user