折腾:
【记录】Mac中折腾Cesium
期间,需要在Mac中搭建一个本地的web server
mac nodejs web server
mac node js web server
Once we have installed Node.js, let’s build our first web server. Create a file named app.jscontaining the following contents:
所以需要先去安装

好像就是node?
那之前已安装过的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | node: stable 13.12.0 (bottled), HEAD Platform built on V8 to build network applications https: //nodejs .org/ /usr/local/Cellar/node/9 .9.0 (5,125 files, 49.7MB) * Poured from bottle on 2018-04-17 at 10:52:40 From: https: //mirrors .ustc.edu.cn /homebrew-core .git /Formula/node .rb ==> Dependencies Build: pkg-config ✘, python ✘ Required: icu4c <img draggable= "false" role= "img" class= "emoji" alt= " src= "https://s.w.org/images/core/emoji/14.0.0/svg/2714.svg" > ==> Options --HEAD Install HEAD version ==> Caveats Bash completion has been installed to: /usr/local/etc/bash_completion .d |
看看版本:
1 2 3 4 | crifan@licrifandeMacBook-Pro ~ node - v v10.4.0 crifan@licrifandeMacBook-Pro ~ npm - v 6.1.0 |
1 | npm install http-server -g |
log
1 2 3 4 5 | crifan@licrifandeMacBook-Pro ~ npm install http-server -g /Users/crifan/ .nvm /versions/node/v10 .4.0 /bin/http-server -> /Users/crifan/ .nvm /versions/node/v10 .4.0 /lib/node_modules/http-server/bin/http-server /Users/crifan/ .nvm /versions/node/v10 .4.0 /bin/hs -> /Users/crifan/ .nvm /versions/node/v10 .4.0 /lib/node_modules/http-server/bin/http-server + http-server@0.12.3 added 23 packages from 35 contributors in 8.218s |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | const http = require( 'http' ); const hostname = '127.0.0.1' ; const port = 3000 ; const server = http.createServer((req, res) = > { res.statusCode = 200 ; res.setHeader( 'Content-Type' , 'text/plain' ); res.end( 'Hello World' ); }); server.listen(port, hostname, () = > { console.log(`Server running at http: / / ${hostname}:${port} / `); }); |
去启动试试

是可以的。
那再去把Cesium的文件,放到同目录?
好像也不对。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | crifan@licrifandeMacBook-Pro ~ http-server --help usage: http-server [path] [options] options: -p --port Port to use [8080] -a Address to use [0.0.0.0] -d Show directory listings [ true ] -i Display autoIndex [ true ] -g --gzip Serve gzip files when possible [ false ] -b --brotli Serve brotli files when possible [ false ] If both brotli and gzip are enabled, brotli takes precedence -e --ext Default file extension if none supplied [none] -s --silent Suppress log messages from output --cors[=headers] Enable CORS via the "Access-Control-Allow-Origin" header Optionally provide CORS headers list separated by commas -o [path] Open browser window after starting the server. Optionally provide a URL path to open the browser window to. -c Cache time (max-age) in seconds [3600], e.g. -c10 for 10 seconds. To disable caching, use -c-1. -t Connections timeout in seconds [120], e.g. -t60 for 1 minute. To disable timeout, use -t0 -U --utc Use UTC time format in log messages. --log-ip Enable logging of the client's IP address -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http: //someurl.com --username Username for basic authentication [none] Can also be specified with the env variable NODE_HTTP_SERVER_USERNAME --password Password for basic authentication [none] Can also be specified with the env variable NODE_HTTP_SERVER_PASSWORD -S --ssl Enable https. -C --cert Path to ssl cert file ( default : cert.pem). -K --key Path to ssl key file ( default : key.pem). -r --robots Respond to /robots.txt [User-agent: *\nDisallow: /] --no-dotfiles Do not show dotfiles -h --help Print this list and exit. -v --version Print the version and exit. |
然后去该目录下运行:
1 2 3 4 5 6 7 8 9 10 | ✘ crifan@licrifandeMacBook-Pro ~/dev/dev_root/projects/cesiumTest http-server -o Starting up http-server, serving ./ Available on: http: //127.0.0.1:8080 http: //192.168.31.12:8080 Hit CTRL-C to stop the server open: http: //127.0.0.1:8080 [Thu Apr 30 2020 21:44:08 GMT+0800 (GMT+08:00)] "GET /" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15" [Thu Apr 30 2020 21:44:09 GMT+0800 (GMT+08:00)] "GET /favicon.ico" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15" [Thu Apr 30 2020 21:44:09 GMT+0800 (GMT+08:00)] "GET /favicon.ico" Error (404): "Not found" |

自动打开页面:

转载请注明:在路上 » 【已解决】Mac中搭建本地NodeJS的web服务器