12345678910111213141516171819202122232425262728293031 |
- /* 注册命名空间 */
- var us = {};
- /* 引用外部模块 */
- var app = require('./lib/main.js');
- us.mysql = require('./mysql.js');
- us.querystring = require('querystring');
- //以当前目录下的demo目录为web应用根目录
- app.baseUrl(__dirname);
- app.use('/', function (req, res) {
- res.writeHead(200, { "Content-Type": "text/html;application/json;charset=utf-8", 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With' });
- debugger;
-
- //querystring.parse可以把形如mode=select&test=1111的字符串拆分成一个json对象,不过这个对象很奇怪,直接输出这个对象会报错
- var _postJson = req.body || req.query; //获取前台数据
- var _usparams = _postJson.mode; //前台传递进来的插入删除等模式
- //console.dir(_usparams);
- if (_usparams) {
- _usparams = _usparams.split(","); //作为一个数组传递,不再拆分,可以让后台极度简化
- //"usgetclientip"
- //console.log(params);
- // console.log(_usparams);
- if (_usparams[2] == "usipaddress") { res.end(req.connection.remoteAddress); } //获取访问者IP
- us.mysql.usselect(_usparams, function (results) { res.end(results); }); //执行Mysql
- }
- });
- app.listen(4444, "nodejs.1473.cn");
- console.log("服务启动成功");
|