| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
前言:作者在 nodejs 开发的时候发现一个问题,就是没有一个好用一点的 Web Server(类似于 IIS) ,有时候写个简单的东西,都要安装一大堆东西。于是作者开发一款 Node Web Server 。 然后发现还是不够好用,但是又不想把 Node Web Server 的代码搞得太复杂,于是对 Node Web Server 进行二次封装,开发了这个名为 Node Web Server Plus 的软件。
Node Web Server 的加强版本,再 Node Web Server 的基础上集成更多的功能。
软件提供了 npm 的安装方式,在控制台输入下面的命令
npm i -g maishu-nwsp
软件提供了命令行的方式来使用
nwsp -d <website path> -p <port>
-d 必填,后面的参数 <website path> 为网站文件夹 -p 可选,后面的参数 <port> 为网站端口,默认值为 9868
一个典型的网站文件夹应该如下:
根目录 ├── controllers | └── home.js ├── node_modules ├── public | └── dynamic | └── index.html └── package.json
示例
下面的示例演示一个最为简单的网页显示
创建一个名为 demo 的文件夹如下:
demo ├── public | └── index.html
index.html 文件
<html>
<head> </head>
<body>
<h1>Hello World</h1>
</body>
</html>运行命令
nwsp -d demo
在浏览器输入 http://127.0.0.1:9868 可以看到
Hello World
文件夹如下
demo ├── public | └── index.html | └── index.ts
index.html 文件
<html>
<head></head>
<body>
<script src="./index.ts"></script>
</body>
</html>index.ts 文件
let hello: string = 'Hello'
let world: string = 'World'
document.body.innerHTML = hello + ' ' + world运行命令
nwsp -d demo
在浏览器输入 http://127.0.0.1:9868 可以看到
Hello World
在浏览器输入 http://127.0.0.1:9868/index.ts 可以看到
'use strict'
let hello = 'Hello'
let world = 'World'
document.body.innerHTML = hello + ' ' + world文件夹如下
demo ├── public | └── index.html | └── index.less
index.html 文件内容如下:
<html>
<head>
<link rel="stylesheet" type="text/css" href="./index.less" />
</head>
<body>
<h1>Hello World</h1>
</body>
</html>index.less 文件内容如下:
@color: red;
h1 {
color: @color;
}运行命令
nwsp -d demo
在浏览器输入 http://127.0.0.1:9868 可以看到红色的 ”Hello World“
node-web-server 支持使用 js 编写的动态脚本文件,动态脚本文件需要放在名为特定的文件夹,该文件夹默认为 dynamic,可以同通过配置修改该文件夹路径。
示例
文件夹如下
demo ├── public | └── dynamic | └── hello-world.js
hello-world.js 文件如下
exports.default = function () {
return {
content: "hello world",
headers: { "Content-Type": "text/plain" }
}
}在浏览器输入:http://127.0.0.1:9868/dynamic/hello-world.js 可以看到:
hello world
| Back | FazBrowse Home | New Git URL |