mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
- add hapi\n- refactor examples
This commit is contained in:
parent
758022871a
commit
ff255f33ee
@ -37,7 +37,7 @@
|
||||
</script>
|
||||
<script>
|
||||
($.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');
|
||||
chat.map().val(function(msg, field){
|
||||
console.log("msg", field, msg);
|
||||
@ -63,4 +63,4 @@
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -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
|
||||
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 http = require('http');
|
||||
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
|
||||
}
|
||||
});
|
||||
var Gun = require('..');
|
||||
|
||||
var app = express();
|
||||
app.use(Gun.serve);
|
||||
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');
|
||||
|
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()
|
@ -20,4 +20,4 @@
|
||||
<a href="/chat/index.html"><iframe src="/chat/index.html"></iframe></a>
|
||||
<script src="../gun.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -26,7 +26,7 @@
|
||||
function clean(text){ return String(text).replace(/\</ig, '<') }
|
||||
</script>
|
||||
<script>
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
var gun = Gun(location.origin);
|
||||
var ref = gun.get('example/json/data');
|
||||
$('#form').onsubmit = function(e){
|
||||
return ref.path( clean($('#field').value) ).put("value"), false; // add a new field, and cancel the form submit.
|
||||
@ -75,4 +75,4 @@
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -11,7 +11,7 @@
|
||||
function clean(text){ return String(text).replace(/\</ig, '<') }
|
||||
</script>
|
||||
<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');
|
||||
$("#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.
|
||||
@ -34,4 +34,4 @@
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
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": {
|
||||
"express": "~>4.13.4",
|
||||
"hapi": "^16.1.0",
|
||||
"inert": "^4.1.0",
|
||||
"ip": "^1.1.4",
|
||||
"mocha": "~>1.9.0",
|
||||
"uglify-js": "~>2.2.0",
|
||||
"panic-manager": "^1.2.0",
|
||||
"panic-server": "^1.1.0",
|
||||
"ip": "^1.1.4"
|
||||
"uglify-js": "~>2.2.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
|
||||
var Gun = require('./root');
|
||||
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'){
|
||||
var gun, back = back || this, cat = back._;
|
||||
var gun, back = this, cat = back._;
|
||||
var next = cat.next || empty, tmp;
|
||||
if(!(gun = next[key])){
|
||||
gun = cache(key, back);
|
||||
|
Loading…
x
Reference in New Issue
Block a user