We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
背景:学习前端开发,想要调试静态页面以及js,发现直接打开本地会有跨域异常,因此需要启动一个静态服务器,只负责当前目录的文件路由,
目前尝试两种方案:
brew install nginx
Mac通过brew安装后的配置文件位于:/usr/local/etc/nginx.
修改端口和文件目录:
server { listen 8090; server_name server.com; charset utf-8; location / { alias /Users/wangyaxing/test/; index index.html; } .... }
# 启动 nginx # 关闭 nginx -s stop
启动后,打开浏览器,输入: localhost:8090/xxx.html即可。
http-server是基于node.js的HTTP 服务器,它最大的好处就是: 可以使用任意一个目录成为服务器的目录,完全抛开后端的沉重工程,直接运行想要的js代码
npm install -g http-server
http-server就可以以 该目录为跟启动一个服务器
该目录
http-server [path] [options]
options更多选项,可以查看http-server
cd test/ http-server -p 8900
你可以把 http-server -p 8900 写入到 package.json 文件中的 scripts 节点
"scripts": { "dev": "http-server -p 8900" },
The text was updated successfully, but these errors were encountered:
No branches or pull requests
如何启动一个本地静态服务器
背景:学习前端开发,想要调试静态页面以及js,发现直接打开本地会有跨域异常,因此需要启动一个静态服务器,只负责当前目录的文件路由,
目前尝试两种方案:
nginx
安装
配置
Mac通过brew安装后的配置文件位于:/usr/local/etc/nginx.
修改端口和文件目录:
启动和关闭
启动后,打开浏览器,输入: localhost:8090/xxx.html即可。
http-server
http-server是基于node.js的HTTP 服务器,它最大的好处就是:
可以使用任意一个目录成为服务器的目录,完全抛开后端的沉重工程,直接运行想要的js代码
安装
启动
http-server就可以以
该目录
为跟启动一个服务器使用
你可以把 http-server -p 8900 写入到 package.json 文件中的 scripts 节点
The text was updated successfully, but these errors were encountered: