本地启动服务访问静态html(访问服务器静态资源)
一、Node环境下启动服务
1、安装node web服务
npm install http-server -g
2、在网页目录下运行web服务
http-server . -p 8000
启动后,浏览器访问 localhost:8000 即可看到网页内容
如果需要在powershell下运行http-server . -p 8000,则如下解决
由于powershell会出现禁止运行脚本的错误,导致无法运行http-server
这是因为power shell的安全策略限制的,,将 其视为了不安全脚本,不允许执行。只需要放开权限就行。
首先通过管理员权限运行power shell,
然后输入命令
set-ExecutionPolicy RemoteSigned
选择“是”,就OK了。
二、python环境下启动服务
如果你已经安装好了Python,只需要从命令行里便可以运行它(从工作目录):
//Python 3.x
python -m http.server启动后,浏览器访问 localhost:8000 即可看到网页内容