.git bash 执行代码生成:

./makeJs.sh

生成文件如下:

访问:http://127.0.0.1:3030/index.html

makeJs.sh  代码如下:

#create makePost.sh

post=./makePost.sh
if [ -f "$post" ];then
echo "$post 文件己存在"
else
(
cat <<EOF
count=1
while [ "$#" -ge "1" ];do
echo "参数序号为 $count 是 $1"
curl -i -X POST -H 'Content-type':'application/json' -d {"BTime":""$btime""} $1 let count=count+1
shift
done
EOF
) > $post
fi #create index.html
index=./index.html
if [ -f "$index" ];then
echo "$index 文件己存在"
else
(
cat <<EOF
testing
EOF
) > $index
fi #create index.js
file=./index.js
if [ -f "$file" ];then
echo "文件己存在!无法生成 $file"
else
(
cat <<EOF
var http=require('http');
var fs = require('fs');
var url = require('url'); http.createServer(function(request,response) {
var pathname= url.parse(request.url).pathname;
console.log("Request for "+ pathname + " received.");
fs.readFile(pathname.substr(1),function(err, data) {
if(err) {
response.writeHead(404,{'Content-Type': 'text/html'});
}
else {
response.writeHead(200,{'Content-Type': 'text/html'});
response.write(data.toString());
}
response.end();
});
}).listen(3030); console.log('Server running at http://127.0.0.1:3030/index.html');
EOF
) > $file echo "文件创建成功"
node index.js fi

  

makeJs.sh 解决服务资源CSS/JS/other  文件载入:(推荐)

// --------
#create makePost.sh post=./makePost.sh
if [ -f "$post" ];then
echo "$post 文件己存在"
else
(
cat <<EOF
count=
while [ "$#" -ge "" ];do
echo "参数序号为 $count 是 $1"
curl -i -X POST -H 'Content-type':'application/json' -d {"BTime":""$btime""} $ let count=count+
shift
done
EOF
) > $post
fi #create index.html
index=./index.html
if [ -f "$index" ];then
echo "$index 文件己存在"
else
(
cat <<EOF
testing
EOF
) > $index
fi #create index.js
file=./index.js
if [ -f "$file" ];then
echo "文件己存在!无法生成 $file"
else
(
cat <<EOF var http = require('http');
var fs = require('fs'); //主要思想就是任何一个静态文件也应该做响应,一个获取静态文件都应当请求来处理,这是主要思想
var server = http.createServer(); var handlerequest = function(request,respone){
var url = request.url,ns;
// respone.writeHead(200,{'Content-Type':'text/html'});
if(url=='/'){
respone.writeHead(,{'Content-Type':'text/html'});
ns = fs.readFile('./index.html', function(err, data) {
if (err) {
console.error(err);
return;
}
respone.end(data);
});
//respone.end();
}else if(url != '/'){
var surl = '.'+url;
var type = surl.substr(surl.lastIndexOf(".")+,surl.length);
respone.writeHead(,{'Content-type':"text/"+type});
// respone.writeHead(200,{'Content-Type':'text/css'});
ns = fs.readFile(surl, function(err, data) {
if (err) {
console.error(err);
return;
}
respone.end(data);
});
}
};
server.on('request',handlerequest); server.listen(,function(){
console.log('Server running at http://127.0.0.1:3030/index.html');
}); EOF
) > $file echo "文件创建成功"
node index.js fi

Post 接口批量测试

./makePost.sh http://192.168.3.52/ad/customer/res

  使用 curl 测试post请求json接口
   

./makePost.sh
count=1
while [ $# -ge "1" ];do
echo "参数序号为 $count 是"
curl -i -X POST -H 'Content-type':'application/json' -d {"BTime":""$btime""} $1
let count=count+1
shift
done

  

Shell 简单构建 Node web服务器的更多相关文章

  1. 一个简单的Java web服务器实现

    前言 一个简单的Java web服务器实现,比较简单,基于java.net.Socket和java.net.ServerSocket实现: 程序执行步骤 创建一个ServerSocket对象: 调用S ...

  2. JSP学习笔记(三):简单的Tomcat Web服务器

    注意:每次对Tomcat配置文件进行修改后,必须重启Tomcat 在E盘的DATA文件夹中创建TomcatDemo文件夹,并将Tomcat安装路径下的webapps/ROOT中的WEB-INF文件夹复 ...

  3. Golang学习-第二篇 搭建一个简单的Go Web服务器

    序言 由于本人一直从事Web服务器端的程序开发,所以在学习Golang也想从Web这里开始学起,如果对Golang还不太清楚怎么搭建环境的朋友们可以参考我的上一篇文章 Golang的简单介绍及Wind ...

  4. C语言构建小型Web服务器

    #include <stdio.h> #include <sys/socket.h> #include <stdlib.h> #include <string ...

  5. Windows窗体应用程序(非Console)使用libuv实现简单的异步WEB服务器

    libuv是一个很强大的异步处理框架(严格意义上不能叫框架,其实就是一组异步函数库,当然框架这东西有各种各样的定义和理解_^...),最初的的目的是用于NODEJS的异步处理,不过因为它是一个独立的项 ...

  6. NODE编程(三)--构建Node Web程序1

    一.HTTP服务器的基本知识 1.Node如何向开发者呈现HTTP请求 Node中的http模块提供了HTTP服务器和客户端接口: var http = require('http'); 创建HTTP ...

  7. python简单搭建HTTP Web服务器

    对于Python 2,简单搭建Web服务器,只需在i需要搭建Web服务器的目录(如C:/ 或 /home/klchang/)下,输入如下命令: python -m SimpleHTTPServer 8 ...

  8. 搭建一个简单的node.js服务器

    第一步:安装node.js.可以去官网:https://nodejs.org/en/进行下载. 查看是否成功,只需在控制台输入 node -v.出现版本号的话,就证明成功了. 第二步:编写node.j ...

  9. node - web 服务器 、server 服务器

    node 作为服务端 - 基本使用 1. web 服务器 web.html <!DOCTYPE html> <html> <head> <meta chars ...

随机推荐

  1. 前端_Bootstrap简单使用

    首先说一下简单使用方法: 1.首先上官网下载Bootstrap(就是一些js文件和一些css文件) ,网址: https://v3.bootcss.com/getting-started/#downl ...

  2. Mysql使用event,类似oracle job

    MySQL从5.1开始支持event功能,类似oracle的job功能.有了这个功能之后我们就可以让MySQL自动的执行数据汇总等功能,不用像以前需要操作的支持了.如linux crontab功能. ...

  3. 简说Java线程的那几个启动方式

    本文首发于本博客 猫叔的博客,转载请申明出处 前言 并发是一件很美妙的事情,线程的调度与使用会让你除了业务代码外,有新的世界观,无论你是否参与但是这对于你未来的成长帮助很大. 所以,让我们来好好看看在 ...

  4. springMVC实现增删改查

    首先需要准备好一张数据库表我这里用emp这张表:具体代码: /* SQLyog 企业版 - MySQL GUI v8.14 MySQL - 5.1.73-community ************* ...

  5. 关于javascript异步

    1.简单的理解 JavaScript是单线程的!总所周知,正常代码是从上而下,一条一条顺序执行的.就好比下楼梯,第一条代码先获得内存或者先执行操作.当遇到漫长的处理操作时(比如读取庞大的文件时,执行大 ...

  6. matlab中的实时音频

    音频系统工具箱™针对实时音频处理进行了优化.audioDeviceReader, audioDeviceWriter, audioPlayerRecorder, dsp.AudioFileReader ...

  7. 阿里云安装MySQL5.7

    长话短说: step1:下载mysql源安装包:wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm ste ...

  8. firewalld防火墙设置

    CentOS7/RHEL7系统默认的iptables管理工具是firewalld,不再是以往的iptables-services,命令用起来也是不一样了,当然你也可以选择卸载firewalld,安装i ...

  9. composer包(发布到github上)同步到Packagist

    在上一篇文章里面,探讨了如何一步步建立composer包–创建你的一个composer包 创建完成后,我们需要做的就是讲自建的包发布到Packagist上.至于说什么是Packagist,这个就不用我 ...

  10. 【博客导航】Nico博客导航汇总

    摘要 介绍本博客关注的内容大类.任务.工具方法及链接,提供Nico博文导航. 导航汇总 [博客导航]Nico博客导航汇总 [导航]信息检索导航 [导航]Python相关 [导航]读书导航 [导航]FP ...