mirror of
https://github.com/amark/gun.git
synced 2025-06-12 09:06:52 +00:00
commit
c4008d935a
@ -1,20 +1,24 @@
|
|||||||
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 Gun = require('../');
|
var Gun = require('../');
|
||||||
|
|
||||||
|
// have to do this before instancing gun(?)
|
||||||
|
Gun.on('out', function(msg){
|
||||||
|
this.to.next( msg );
|
||||||
|
msg = JSON.stringify(msg);
|
||||||
|
gunPeers.forEach( function(peer){ peer.send( msg ) })
|
||||||
|
})
|
||||||
|
|
||||||
var gun = Gun({
|
var gun = Gun({
|
||||||
file: 'data.json',
|
file: 'data.json'
|
||||||
s3: {
|
|
||||||
key: '', // AWS Access Key
|
|
||||||
secret: '', // AWS Secret Token
|
|
||||||
bucket: '' // The bucket you want to save into
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var server = require('http').createServer(function(req, res){
|
var server = require('http').createServer(function(req, res){
|
||||||
if(gun.wsp.server(req, res)){
|
var insert = "";
|
||||||
return; // filters gun requests!
|
if( req.url.endsWith( "gun.js" ) )
|
||||||
}
|
insert = "../";
|
||||||
require('fs').createReadStream(require('path').join(__dirname, req.url)).on('error',function(){ // static files!
|
|
||||||
|
require('fs').createReadStream(require('path').join(__dirname, insert, req.url)).on('error',function(){ // static files!
|
||||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||||
res.end(require('fs').readFileSync(require('path').join(__dirname, 'index.html'))); // or default to index
|
res.end(require('fs').readFileSync(require('path').join(__dirname, 'index.html'))); // or default to index
|
||||||
}).pipe(res); // stream
|
}).pipe(res); // stream
|
||||||
@ -35,10 +39,6 @@ wss.on('connection',acceptConnection )
|
|||||||
|
|
||||||
var gunPeers = []; // used as a list of connected clients.
|
var gunPeers = []; // used as a list of connected clients.
|
||||||
|
|
||||||
Gun.on('out', function(msg){
|
|
||||||
msg = JSON.stringify(msg);
|
|
||||||
gunPeers.forEach( function(peer){ peer.send( msg ) })
|
|
||||||
})
|
|
||||||
function acceptConnection( connection ) {
|
function acceptConnection( connection ) {
|
||||||
// connection.upgradeReq.headers['sec-websocket-protocol'] === (if present) protocol requested by client
|
// connection.upgradeReq.headers['sec-websocket-protocol'] === (if present) protocol requested by client
|
||||||
// connection.upgradeReq.url === url request
|
// connection.upgradeReq.url === url request
|
||||||
|
Loading…
x
Reference in New Issue
Block a user