mirror of
https://github.com/amark/gun.git
synced 2025-10-14 00:59:35 +00:00
touching app.js
This commit is contained in:
parent
b83b13a1b9
commit
93e34f364b
10
.travis.yml
10
.travis.yml
@ -1,6 +1,6 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- 0.6
|
- 0.6
|
||||||
- 0.8
|
- 0.8
|
||||||
- 0.10
|
- 0.10
|
||||||
- 0.11
|
- 0.11
|
130
README.md
130
README.md
@ -1,65 +1,65 @@
|
|||||||
gun [](https://travis-ci.org/amark/gun)
|
gun [](https://travis-ci.org/amark/gun)
|
||||||
===
|
===
|
||||||
|
|
||||||
Quick getting started guide.
|
Quick getting started guide.
|
||||||
|
|
||||||
Make sure you already have node and npm installed.
|
Make sure you already have node and npm installed.
|
||||||
|
|
||||||
`npm install gun`
|
`npm install gun`
|
||||||
|
|
||||||
Then require it in your app.
|
Then require it in your app.
|
||||||
|
|
||||||
`var Gun = require('gun');`
|
`var Gun = require('gun');`
|
||||||
|
|
||||||
Then initialize a gun instance with your AWS S3 credentials.
|
Then initialize a gun instance with your AWS S3 credentials.
|
||||||
|
|
||||||
```JavaScript
|
```JavaScript
|
||||||
var gun = Gun({
|
var gun = Gun({
|
||||||
s3: {
|
s3: {
|
||||||
key: '', // AWS Access Key
|
key: '', // AWS Access Key
|
||||||
secret: '', // AWS Secret Token
|
secret: '', // AWS Secret Token
|
||||||
bucket: '' // The bucket you want to save into
|
bucket: '' // The bucket you want to save into
|
||||||
}});
|
}});
|
||||||
```
|
```
|
||||||
|
|
||||||
S3 is the default persistence layer, it can be replaced with others.
|
S3 is the default persistence layer, it can be replaced with others.
|
||||||
|
|
||||||
Currently, gun is only key/value but graph support is coming soon.
|
Currently, gun is only key/value but graph support is coming soon.
|
||||||
|
|
||||||
Save your first object, and create a reference to it.
|
Save your first object, and create a reference to it.
|
||||||
|
|
||||||
`gun.set({ hello: 'world' }).key('my/first/data');`
|
`gun.set({ hello: 'world' }).key('my/first/data');`
|
||||||
|
|
||||||
Now, altogether, with the node hello world web server that replies with your data.
|
Now, altogether, with the node hello world web server that replies with your data.
|
||||||
|
|
||||||
```JavaScript
|
```JavaScript
|
||||||
var Gun = require('gun');
|
var Gun = require('gun');
|
||||||
var gun = Gun({
|
var gun = Gun({
|
||||||
s3: {
|
s3: {
|
||||||
key: '', // AWS Access Key
|
key: '', // AWS Access Key
|
||||||
secret: '', // AWS Secret Token
|
secret: '', // AWS Secret Token
|
||||||
bucket: '' // The bucket you want to save into
|
bucket: '' // The bucket you want to save into
|
||||||
}});
|
}});
|
||||||
gun.set({ hello: 'world' }).key('my/first/data');
|
gun.set({ hello: 'world' }).key('my/first/data');
|
||||||
|
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
gun.load('my/first/data', function(data){
|
gun.load('my/first/data', function(data){
|
||||||
res.writeHead(200, {'Content-Type': 'application/json'});
|
res.writeHead(200, {'Content-Type': 'application/json'});
|
||||||
res.end(JSON.stringify(data));
|
res.end(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
}).listen(1337, '127.0.0.1');
|
}).listen(1337, '127.0.0.1');
|
||||||
console.log('Server running at http://127.0.0.1:1337/');
|
console.log('Server running at http://127.0.0.1:1337/');
|
||||||
```
|
```
|
||||||
|
|
||||||
Now fire up your browser and hit that URL - you'll see your data, plus some gun specific metadata.
|
Now fire up your browser and hit that URL - you'll see your data, plus some gun specific metadata.
|
||||||
|
|
||||||
## Ahead
|
## Ahead
|
||||||
- Realtime push to the browser
|
- Realtime push to the browser
|
||||||
- Persistence in the browser
|
- Persistence in the browser
|
||||||
- Authorization callbacks
|
- Authorization callbacks
|
||||||
- Graph manipulation
|
- Graph manipulation
|
||||||
- Server to server communication
|
- Server to server communication
|
||||||
- Test more
|
- Test more
|
||||||
- Bug fixes
|
- Bug fixes
|
||||||
- More via additional module hooks (schema, queries, etc.)
|
- More via additional module hooks (schema, queries, etc.)
|
||||||
|
@ -1,25 +1,26 @@
|
|||||||
console.log("If modules not found, run `npm install` in example/admin folder!");
|
console.log("HEY YOU");
|
||||||
|
console.log("If modules not found, run `npm install` in example/admin folder!");
|
||||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || 8888;
|
|
||||||
var express = require('express');
|
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || 8888;
|
||||||
var bodyParser = require('body-parser');
|
var express = require('express');
|
||||||
var app = express();
|
var bodyParser = require('body-parser');
|
||||||
var Gun = require('gun');
|
var app = express();
|
||||||
var gun = Gun({
|
var Gun = require('gun');
|
||||||
peers: 'http://localhost:' + port + '/gun'
|
var gun = Gun({
|
||||||
,s3: require('../../test/shotgun') // replace this with your own keys!
|
peers: 'http://localhost:' + port + '/gun'
|
||||||
});
|
,s3: require('../../test/shotgun') // replace this with your own keys!
|
||||||
|
});
|
||||||
app.use(express.static(__dirname))
|
|
||||||
.use(bodyParser.json())
|
app.use(express.static(__dirname))
|
||||||
.use(gun.server);
|
.use(bodyParser.json())
|
||||||
app.listen(port);
|
.use(gun.server);
|
||||||
|
app.listen(port);
|
||||||
console.log('Express started on port ' + port + ' with /gun');
|
|
||||||
|
console.log('Express started on port ' + port + ' with /gun');
|
||||||
gun.load('blob/data', function(){ // ugh need to initialize the data if there is none, what a waste of LOC!
|
|
||||||
gun.set({_:{'#': "yVbyf7BqlXVQQUOE5cw9rf8h",'>':{hello: 1407328713707,from: 1407328713707}}, // this is a nasty trick to force the ID to overwrite itself
|
gun.load('blob/data', function(){ // ugh need to initialize the data if there is none, what a waste of LOC!
|
||||||
hello: "world",
|
gun.set({_:{'#': "yVbyf7BqlXVQQUOE5cw9rf8h",'>':{hello: 1407328713707,from: 1407328713707}}, // this is a nasty trick to force the ID to overwrite itself
|
||||||
from: "Mark Nadal"
|
hello: "world",
|
||||||
}).key('blob/data');
|
from: "Mark Nadal"
|
||||||
|
}).key('blob/data');
|
||||||
});
|
});
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "admin",
|
"name": "admin",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "~>4.9.0",
|
"express": "~>4.9.0",
|
||||||
"body-parser": "~>1.8.1",
|
"body-parser": "~>1.8.1",
|
||||||
"gun": "~>0.0.2b"
|
"gun": "~>0.0.2b"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,64 +1,64 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<style>
|
<style>
|
||||||
.table li {
|
.table li {
|
||||||
float: left;
|
float: left;
|
||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
}
|
}
|
||||||
ul, li {
|
ul, li {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
}
|
}
|
||||||
.clear {
|
.clear {
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
.none {
|
.none {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<ul>
|
<ul>
|
||||||
<li><ul class="table none">
|
<li><ul class="table none">
|
||||||
<li>Seconds in month:</li>
|
<li>Seconds in month:</li>
|
||||||
<li><input type="number" value="2629743.83" id="sim"></li>
|
<li><input type="number" value="2629743.83" id="sim"></li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li class="clear"></li>
|
<li class="clear"></li>
|
||||||
<li><ul class="table">
|
<li><ul class="table">
|
||||||
<li>Persist every seconds:</li>
|
<li>Persist every seconds:</li>
|
||||||
<li><input type="number" value="15" id="se"></li>
|
<li><input type="number" value="15" id="se"></li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li class="clear"></li>
|
<li class="clear"></li>
|
||||||
<li><ul class="table">
|
<li><ul class="table">
|
||||||
<li>Over how many objects:</li>
|
<li>Over how many objects:</li>
|
||||||
<li><input type="number" value="100" id="o"></li>
|
<li><input type="number" value="100" id="o"></li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li class="clear"></li>
|
<li class="clear"></li>
|
||||||
<li><ul class="table">
|
<li><ul class="table">
|
||||||
<li>Cost $:</li>
|
<li>Cost $:</li>
|
||||||
<li><input type="number" value="" readonly id="r"></li>
|
<li><input type="number" value="" readonly id="r"></li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
<p>
|
<p>
|
||||||
This page is for throughput calculation, it assumes continuous load non-stop.
|
This page is for throughput calculation, it assumes continuous load non-stop.
|
||||||
</p>
|
</p>
|
||||||
<script>
|
<script>
|
||||||
$(function(){
|
$(function(){
|
||||||
var sim = $('#sim')
|
var sim = $('#sim')
|
||||||
, se = $('#se')
|
, se = $('#se')
|
||||||
, o = $('#o')
|
, o = $('#o')
|
||||||
, r = $('#r')
|
, r = $('#r')
|
||||||
, n = function(n){ return parseFloat(n) }
|
, n = function(n){ return parseFloat(n) }
|
||||||
$(document).on('keyup', function(){
|
$(document).on('keyup', function(){
|
||||||
r.val(
|
r.val(
|
||||||
(( n(sim.val()) / n(se.val()) ) * n(o.val()) / 1000 * 0.005 ).toFixed(2)
|
(( n(sim.val()) / n(se.val()) ) * n(o.val()) / 1000 * 0.005 ).toFixed(2)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -1,17 +1,17 @@
|
|||||||
var Gun = require('gun');
|
var Gun = require('gun');
|
||||||
var gun = Gun({
|
var gun = Gun({
|
||||||
s3: {
|
s3: {
|
||||||
key: '', // AWS Access Key
|
key: '', // AWS Access Key
|
||||||
secret: '', // AWS Secret Token
|
secret: '', // AWS Secret Token
|
||||||
bucket: '' // The bucket you want to save into
|
bucket: '' // The bucket you want to save into
|
||||||
}});
|
}});
|
||||||
gun.set({ hello: 'world' }).key('my/first/data')
|
gun.set({ hello: 'world' }).key('my/first/data')
|
||||||
|
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
gun.load('my/first/data', function(data){
|
gun.load('my/first/data', function(data){
|
||||||
res.writeHead(200, {'Content-Type': 'application/json'});
|
res.writeHead(200, {'Content-Type': 'application/json'});
|
||||||
res.end(JSON.stringify(data));
|
res.end(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
}).listen(1337, '127.0.0.1');
|
}).listen(1337, '127.0.0.1');
|
||||||
console.log('Server running at http://127.0.0.1:1337/');
|
console.log('Server running at http://127.0.0.1:1337/');
|
@ -5,12 +5,12 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
font-family: 'Segoe UI', Tahoma;
|
font-family: 'Segoe UI', Tahoma;
|
||||||
font-size: 20pt;
|
font-size: 20pt;
|
||||||
color: #222;
|
color: #222;
|
||||||
}
|
}
|
||||||
@media (max-width: 1000px){
|
@media (max-width: 1000px){
|
||||||
html, body {
|
html, body {
|
||||||
@ -32,18 +32,18 @@
|
|||||||
-moz-animation: fade 7s;
|
-moz-animation: fade 7s;
|
||||||
animation: fade 7s;
|
animation: fade 7s;
|
||||||
}
|
}
|
||||||
.big {
|
.big {
|
||||||
font-size: 300%;
|
font-size: 300%;
|
||||||
}
|
}
|
||||||
.small {
|
.small {
|
||||||
font-size: 75%;
|
font-size: 75%;
|
||||||
}
|
}
|
||||||
.break {
|
.break {
|
||||||
border: none;
|
border: none;
|
||||||
border-bottom: dashed 5px gainsboro;
|
border-bottom: dashed 5px gainsboro;
|
||||||
}
|
}
|
||||||
.bump {
|
.bump {
|
||||||
height: 20%;
|
height: 20%;
|
||||||
}
|
}
|
||||||
|
|
||||||
@-webkit-keyframes fade {
|
@-webkit-keyframes fade {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user