Created
September 2, 2016 14:52
-
-
Save tnrn9b/c22ea28617598d7550b7305507925a50 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
const http = require('http'); | |
const http = require('http'); | |
const fs = require('fs'); | |
const url = require('url'); | |
var db = require('/QOpenSys/QIBM/ProdData/Node/os400/db2i/lib/db2'); | |
var xt = require('/QOpenSys/QIBM/ProdData/Node/os400/xstoolkit/lib/itoolkit'); | |
var DBname = "*LOCAL"; | |
var ip = "IP_ADDRESS"; | |
var port = PORT; | |
var webserver = http.createServer(function (req, res) { | |
var realPath = __dirname + url.parse(req.url).pathname; | |
fs.exists(realPath,function(exists){ | |
if(!exists){ | |
var sql = url.parse(req.url, true).query.sql; | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
if(sql && sql.length > 0) { | |
console.log("SQL statement : " + sql); | |
db.init(); | |
db.conn(DBname); | |
db.exec(sql, function(rs) { | |
res.write(JSON.stringify(rs)); | |
}); | |
db.close(); | |
} | |
res.end(); | |
} else { | |
var file = fs.createReadStream(realPath); | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
file.on('data', res.write.bind(res)); | |
file.on('close', res.end.bind(res)); | |
file.on('error', function(err){ | |
res.writeHead(500, {'Content-Type': 'text/plain'}); | |
res.end("500 Internal Server Error"); | |
}); | |
} | |
}); | |
}); | |
webserver.listen(port, ip); | |
console.log('DB Browser Access at http://' + ip + ':' + port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment