Created
December 14, 2020 14:24
-
-
Save gfwilliams/25fa436dcaa4f45e64eb429e1d075956 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WIFI_NAME = "BTHub4-XFTX"; | |
var WIFI_PASS = "735dfd986d"; | |
// var re = /:[^/]+/g; needs changing to | |
// var re = /:[^\/]+/g; | |
var wifi = require("Wifi"); | |
wifi.connect(WIFI_NAME, { password : WIFI_PASS }, function(err) { | |
if (err) { | |
console.log("Connection error: "+err); | |
return; | |
} | |
console.log("Connected!"); | |
main(); | |
}); | |
var fs = require('fs'); | |
var Express = require('https://raw.githubusercontent.com/rzr/iotjs-express/master/lib/express.js'); | |
function main() { | |
var port = 8080; | |
var db = {}; | |
var app = new Express(); | |
app.set('x-powered-by'); | |
app.get('/', function(req, res) { | |
return res.json({}); | |
}); | |
app.get('/.well-known/security.txt', function(req, res) { | |
return res.end('Contact: https://www.npmjs.com/~rzr\n'); | |
}); | |
app.put('/db/:key', function(req, res) { | |
console.log(req.body); | |
db[req.params.key] = req.body.value; | |
return res.json(db); | |
}); | |
app.get('/~:user', function(req, res) { | |
return res.json({user: req.params.user}); | |
}); | |
app.listen(port); | |
wifi.getIP(function(err,n) { | |
console.log('Listening on:\nhttp://'+n.ip+':' + port); | |
}) | |
} | |
// polyfill | |
String.prototype.concat = function() { | |
return this+arguments.join(""); | |
}; | |
var Buffer = { | |
byteLength : function(x) { return x.length; } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment