123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- var http = require('http');
- var fs = require('fs');
- var con = require('./conn.js');
- global.data1 = con.e;
- var server = http.createServer();
- server.listen(8082, function(){
- console.log('服务器正在端口8082上运行......');
- })
- server.on('request',function(request,response){
-
- var url = request.url;
- if(url ==='/'){
- //response.writeHead(响应状态码,响应头对象): 发送一个响应头给请求。
- response.writeHead(200,{'Content-Type':'text/html'})
- // 如果url=‘/' ,读取指定文件下的html文件,渲染到页面。
- fs.readFile('./practice/login.html','utf-8',function(err,data){
- if(err){
- throw err ;
- }
- response.end(data);
- });
-
- }else if(url === '/login'){
- response.writeHead(200,{'Content-Type':'text/html'});
- // 如果url=‘/' ,读取指定文件下的html文件,渲染到页面。
- fs.readFile('./practice/login.html','utf-8',function(err,data){
- if(err){
- throw err ;
- }
- response.end(data);
- });
- }else if(url === '/index'){
- response.writeHead(200,{'Content-Type':'text/html'});
- // 如果url=‘/' ,读取指定文件下的html文件,渲染到页面。
-
- var con = require('./conn.js');
- fs.readFile('./practice/index2.html','utf-8',function(err,data){
- if(err){
- throw err ;
- }
- response.end(data);
- });
- /*
- var con = require('./conn.js');
- var s = '';
- for(var i = 0; i < con.e.length; i++)
- {
-
- s+='<tr>'
- +'<td>' + con.e[i]['userid'] + '</td>'
- +'<td>' + con.e[i]['ip'] + '</td>'
- +'<td>' + con.e[i]['monitorTime'] + '</td>'
- +'<td>' + con.e[i]['jyjid'] + '</td>'
- +'<td>' + con.e[i]['jyqid'] + '</td>'
- +'<td>' + con.e[i]['al'] + '</td>'
- +'<td>' + con.e[i]['qll'] + '</td>'
- +'<td>' + con.e[i]['yll'] + '</td>'
- +'</tr>'
- }
- var t = '<table border="1">'
- +' <tr>'
- +'<th>用户标识</th>'
- +'<th>ip</th>'
- +'<th>时间</th>'
- +'<th>油机</th>'
- +'<th>油枪</th>'
- +'<th>气液比</th>'
- +'<th>气流量</th>'
- +'<th>油流量</th>'
- +'</tr>'
- +s
- +'</table>';
- var html = '<html>'
- +'<head>'
- +'<title>nodejs</title>'
- +'<meta charset="utf-8"> '
- +'</head>'
- +'<body>'
- //+ s
- + t
- +'</body>'
- response.end(html);
- */
- }else{
- response.writeHead(200,{'Content-Type':'text/html'});
- // 如果url=‘/' ,读取指定文件下的html文件,渲染到页面。
- fs.readFile('./practice/'+request.url,'utf-8',function(err,data){
- if(err){
- throw err ;
- }
- response.end(data);
- });
- }
-
- });
|