Run a file:// from http://localhost/

别说谁变了你拦得住时间么 提交于 2021-02-19 02:59:31

问题


I wonder to know how can I make my .html project run not from file:// but as a localhost because one of the functions I've implemented requires getUserMedia which browsers instantly block, when loading from file://. I've done a lot of research on this but I'm still not understanding how it should be done, so if you can, please explain it in detail if it's not too pretentious of me, of course.


回答1:


If you are on Ubuntu (or any other similar Linux distro) run

apt-get install apache2

then move your files to the /var/www/html folder, and navigate to localhost in your browser.

On Windows, you can install XAMPP, then move your files to wherever you installed it to in the \htdocs folder

Hope this helps, thanks.




回答2:


install node js

npm install -g http-server

from the directory containing html files.

http-server ./ -p 80

reference https://github.com/indexzero/http-server




回答3:


I use live-server on my mac by running the below code on the command line from inside the folder containing your index.html:

live-server --port=8000

In addition to running index.html from localhost, live-server automatically reloads the page after any changes made to files that affect the dome for that page (i.e. .js or .css etc..) which can accelerate development.

Installation

You should probably install this globally.

npm install -g live-server

note:

  • You need node.js in order to use npm.
  • --port= can be any free port and not nessessarly 8000.



回答4:


python -m SimpleHTTPServer 8000

And you are good to go!

Start a server within seconds!

Note you do require an installed python



来源:https://stackoverflow.com/questions/32332485/run-a-file-from-http-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!