Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ node_modules
./bitauth.js
./bitauth.min.js
./tests.js


/examples/bundle.js
2 changes: 1 addition & 1 deletion examples/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ for(k in keys) {
}
if(body) {
console.log(body);
}
}
});
}
11 changes: 11 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>BitAuth Example</title>
</head>
<body>
<div>Open the JS console, that's where the action is :)</div>
<script src="bundle.js"></script>
</body>
</html>
15 changes: 13 additions & 2 deletions examples/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var express = require('express');
var bodyParser = require('body-parser');
var rawBody = require('../lib/middleware/rawbody');
var bitauthMiddleware = require('../lib/middleware/bitauth');
var path = require('path')

var users = {
'Tf7UNQnxB8SccfoyZScQmb34V2GdEtQkzDz': {name: 'Alice'},
Expand All @@ -14,7 +15,6 @@ var app = express();
app.use(rawBody);
app.use(bodyParser());


app.get('/user', bitauthMiddleware, function(req, res) {
if(!req.sin || !users[req.sin]) return res.send(401, {error: 'Unauthorized'});
res.send(200, users[req.sin]);
Expand All @@ -32,4 +32,15 @@ app.get('/pizzas', function(req, res) {
res.send(200, pizzas);
});

app.listen(3000);
app.get('/', function(req, res) {
res.sendFile(path.resolve(__dirname, 'index.html'))
});

app.get('/bundle.js', function(req, res) {
res.sendFile(path.resolve(__dirname, 'bundle.js'))
});

var port = 3000;
app.listen(port, function() {
console.log('Listening on http://localhost:' + port)
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
],
"scripts": {
"make-dist": "gulp browser",
"test": "gulp test"
"test": "gulp test",
"examples": "npm run examples:client:build && npm run examples:server",
"examples:client:build": "browserify examples/client.js -o examples/bundle.js",
"examples:server": "node examples/server.js"
},
"main": "index.js",
"version": "0.3.2",
Expand Down