Skip to content

Instantly share code, notes, and snippets.

@gfwilliams
Created December 14, 2020 14:24
Show Gist options
  • Save gfwilliams/25fa436dcaa4f45e64eb429e1d075956 to your computer and use it in GitHub Desktop.
Save gfwilliams/25fa436dcaa4f45e64eb429e1d075956 to your computer and use it in GitHub Desktop.
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