-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Servidor local
Algunas funciones (como cargar archivos externos, por ejemplo) funcionan según lo esperado cuando los archivos son ubicados en línea a través de FTP o SSH. Sin embargo, si estás tratando de revisarlos localmente, verás algún error del tipo "cross-origin" (origen cruzado) en la consola. La solución a esto es usar lo que se conoce como un servidor web local. Este tutorial incluye instrucciones para configurar distintos tipos de servidores web locales en Mac OSX, Windows y Linux.
Si necesitas ejecutar rápidamente un servidor web y no quieres molestarte en configurar apache o algo similar, Python te puede ayudar. Python incluye un servidor HTTP simple. Con la ayuda de este pequeño servidor HTTP puedes transformar cualquier directorio en tu sistema en un directorio de un servidor web. Lo único que necesitas es tener instalado Python (Python ya viene instalado en Mac OS X).
Tutorial de Python SimpleHTTPServer
Escribe en Terminal:
python -m SimpleHTTPServer
O escribe esto si estás usando Python 3:
python -m http.server
A continuación visita http://localhost:8000
en tu navegador.
Desafortunadamente el servidor simple de Python es muy lento. Cargar una página local a menudo no funcionará y no podrá transmitir video y tendrá problemas con archivos medianos como un mp3 de 8MB, por ejemplo. Sin embargo, será suficiente para cargar la mayoría de los textos, tipografías e imágenes.
An alternative is node.js http-server. It is much faster than python simple server while requiring a little bit of setup. Just 3 simple steps:
-
Open a terminal or command prompt
-
On OSX/Linux type
sudo npm install -g http-server
On Windows type (you might need to open the command prompt as admin)
npm install -g http-server
Done!
From then on just cd
to the folder that has the files you want to serve and type
http-server
Then point your browser at http://localhost:8080/
Note: If you are having problems where the browser does not reload your javascript files after changes are made, you may need to instantiate the server with a specific cache value. To do this, include the cache timeout flag, with a value of '-1'. This tells the browser not to cache files (like sketch.js).
http-server -c-1
Simple HTTPServer library for processing. Allows communication in both ways.
import http.*;
SimpleHTTPServer server;
void setup() {
// Create a server listening on port 8000
// serving index.html,which is in the data folder
server = new SimpleHTTPServer(this);
}
Library page of Processing simple HTTP server
Python SimpleHTTPServer is great to get started, but at some point you might want to set up an Apache server. The Apache server supports a greater range of HTTP functionality and scales well for bigger projects. See below for OS specific setup.
Mac OS X since 10.5 Leopard ships with Apache web server installed, all you have to do is enable it and place the files in the right place.
- Open Terminal and type:
sudo apachectl start
- Verify it is working by going to
http://localhost
on your browser. You should see "It works!" on the browser. - Enable permissions for the files on the server by typing the following two commands into Terminal:
sudo chown root:<your username> -R /Library/WebServer/Documents
sudo chmod -R 755 /Library/WebServer/Documents
- Place your project somewhere inside /Library/WebServer/Documents/.
- View it at http://localhost/(the project folder in /Library/WebServer/Documents).
http://localhost/my-p5-sketch
- Turn on the web server. Go into System Preferences > Sharing, and check the “Web Sharing” box.
- Verify it is working by going to
http://localhost/~<your username>
on your browser. You should see a default webpage with a title of "Your Website". - Place your project somewhere inside
<your username folder>/Sites
. - View it at http://localhost/~(your username)/(the project folder in
<your username folder>/Sites
).
http://localhost/~macusername/my-p5-sketch
- Download WampServer from http://www.wampserver.com/en/.
- Install WampServer and follow instructions.
- The “www” directory will be automatically created (usually c:\wamp\www).
- Create a subdirectory in “www” and put your HTML/JS files inside.
- Open your internet browser and go to the URL : http://localhost/yourfile.html.
- Install apache2 via apt-get.
- Place your project somewhere inside /var/www/.
- View it at http://localhost.
PHP has (since version 5.4.0) a built-in web server for testing purposes that can be used to test P5.js sketches.
To check if you have PHP installed you can open a terminal and issue the command:
php -version
If you have PHP CLI (Command Line Interpreter) installed you can start a local development server by usingd the command:
php -S localhost:8000
Then point your browser at http://localhost:8000/
If you would like to edit this wiki and don't already have edit access, please open an issue or comment on an existing one noting the wiki page you'd like to edit. You will then be added as a repository contributor with edit access.