Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 862
KDX2 Avatar asked Sep 01 '15 13:09

KDX2


2 Answers

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

like image 66
corn3lius Avatar answered Sep 24 '22 05:09

corn3lius


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.
like image 24
Hassan AlMandil Avatar answered Sep 26 '22 05:09

Hassan AlMandil