测试环境:ubuntu 16
node Version : v10.15.0
js中的enum采用var定义实现
var CMD = {
"sys_username_passwd" :0
};
console.log(CMD['sys_username_passwd'])
js对字符串的处理,trim 只是对空白进行处理,取片段使用slice
cmd1.slice(1,-4)
nodejs server响应需要对json单独处理:
if(pathName.endsWith('.cmd')){
var cmd1 = pathName
console.log('cmd recorded: '+ cmd1.slice(1,-4))
switch(CMD[cmd1.slice(1,-4)]){
case CMD.sys_username_passwd:
response.writeHead(200, {"content-type": contentType});
var perm1 ={"permission":3,"name":"admin","password":"xxxx"};
var perm2 ={"permission":3,"name":"admin1","password":"xxxx"};
var perm = [perm1,perm2];
var jsonRes = JSON.stringify({
"NameAndPasswd":perm,
"awk":"xxx",
"set_result":"xxx"
});
response.write(jsonRes);
response.end();
}
}