代码拉取完成,页面将自动刷新
同步操作将从 好雨科技/nodejs-demo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
//var querystring = require("querystring");
var fs = require("fs");
var mysql = require("mysql");
let mysql_table;
function start(response, postData) {
console.log("Request handler 'start' was called.");
//读取HTML文件内容
fs.readFile("./index.html", "utf-8", function(err, data) {
if (err) {
console.error(err);
} else {
response.writeHead(200, { "Content-Type": "text/html" });
response.write(data);
response.end();
}
});
}
function api(response, postData) {
fs.readFile("./apiInstance.html", "utf-8", function(err, data) {
if (err) {
console.error(err);
} else {
response.writeHead(200, { "Content-Type": "text/html" });
response.write(data);
response.end();
}
});
}
function env(response, postData) {
fs.readFile("./MySQL.html", "utf-8", function(err, data) {
if (err) {
console.error(err);
} else {
response.writeHead(200, { "Content-Type": "text/html" });
let top = 25;
// let top1 = 20;
// Object.keys(process.env).map((item)=>{
// top1 +=4
// response.write(`
// <div style="position:absolute;top:${top1}%;padding:0 36px">
// <div> ${item} : ${process.env[item]} </div>
// </div>
// `)
// })
if(Object.keys(process.env).indexOf('MYSQL_HOST') > -1){
var db_config = {
host: process.env['MYSQL_HOST'],
user: process.env['MYSQL_USER'],
password: process.env['MYSQL_PASS'],
database: process.env['MYSQL_DATABASE'],
port: process.env['MYSQL_PORT']
};
var connection = mysql.createConnection(db_config);
connection.connect();
connection.query('show tables ;', function (error, results, fields) {
if (error) console.log(error);
// response.write('-------->'+results);
mysql_table = results;
});
if(mysql_table){
mysql_table.map((item,index)=>{
response.write(
`<div style="position:absolute;top:15%;padding:0 36px">
数据库已连接:
<div style="border:1px solid #eee">${JSON.stringify(item)}</div>
</div>
`
);
})
response.write(
`<div style="position:absolute;top:${top}%;padding:0 36px">
数据库连接信息:
<div style="border:1px solid #eee">MYSQL_HOST: ${process.env['MYSQL_HOST']}</div>
<div style="border:1px solid #eee">MYSQL_DATABASE: ${process.env['MYSQL_DATABASE']}</div>
<div style="border:1px solid #eee">MYSQL_USER: ${process.env['MYSQL_USER']}</div>
<div style="border:1px solid #eee">MYSQL_PASSWORD: ${process.env['MYSQL_PASS']}</div>
<div style="border:1px solid #eee">MYSQL_PORT: ${process.env['MYSQL_PORT']}</div>
</div>`
);
//所有了解信息
// Object.keys(process.env).map((item)=>{
// response.write(`
// <div> ${item}: ${process.env[item]} </div>
// `)
// })
}
else{
response.write(
`<div style="position:absolute;top:${top}%"">数据库未连接。</div>`
);
}
}
else{
response.write(
`<div style="position:absolute;top:${top}%;padding:0 36px">数据库未连接。</div>`
);
}
response.write(data);
// response.write(`<div style="position:absolute;top:15%">${JSON.stringify(Object.keys(process.env))}</div>`)
response.end();
}
});
}
function upload(response, postData) {
console.log("Request handler 'upload' was called.");
response.writeHead(200, { "Content-Type": "text/plain" });
response.write("You've sent: " + postData);
response.end();
}
exports.start = start;
exports.upload = upload;
exports.api = api;
exports.env = env;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。