提交 003f120a 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #10428 from looeee/manual/Movepage/runningLocally

Moved page "How to run things locally" from wiki to manual
......@@ -9,6 +9,7 @@ var list = {
[ "Creating Text", "manual/introduction/Creating-text" ],
[ "Code Style Guide", "manual/introduction/Code-style-guide" ],
[ "Migration Guide", "manual/introduction/Migration-guide" ],
[ "How to run things locally", "manual/introduction/How-to-run-thing-locally" ],
[ "Matrix transformations", "manual/introduction/Matrix-transformations" ],
[ "FAQ", "manual/introduction/FAQ" ]
],
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<base href="../../" />
<script src="list.js"></script>
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
<h1>[name]</h1><br />
<p>If you use just procedural geometries and don't load any textures, webpages should work straight from the file system, just double-click on HTML file in a file manager and it should appear working in the browser (accessed as <code>file:///example</code>).</p>
<h2>Content loaded from external files</h2>
<p>If you load models or textures from external files, due to browsers' "<a href="http://en.wikipedia.org/wiki/Same_origin_policy">same origin policy</a>" security restrictions, loading from a file system will fail with a security exception.</p>
<p>There are two ways how to solve this:</p>
<ol>
<li><p>Change security for local files in a browser (access page as <code>file:///example</code>)</p></li>
<li><p>Run files from a local server (access page as <code>http://localhost/example</code>)</p></li>
</ol>
<p>If you use option 1, be aware that you may open yourself to some vulnerabilities if using the same browser for a regular web surfing. You may want to create a separate browser profile / shortcut used just for local development to be safe.</p>
<hr>
<h3>Change local files security policy</h3>
<h4>Safari</h4>
<p>Enable the develop menu using the preferences panel, under Advanced -&gt; "Show develop menu in menu bar"</p>
<p>Then from the safari "Develop" menu, select "Disable local file restrictions", it is also worth noting safari has some odd behaviour with caches, so it is advisable to use the "Disable caches" option in the same menu; if you are editing &amp; debugging using safari.</p>
<h4>Chrome</h4>
<p>Close all running Chrome instances first. The important word here is 'all'.</p>
<p>On Windows, you may check for Chrome instances using the Windows Task Manager. Alternatively, if you see a Chrome icon in the system tray, then you may open its context menu and click 'Exit'. This should close all Chrome instances.</p>
<p>Then start the Chrome executable with a command line flag:</p>
<pre><code>chrome --allow-file-access-from-files
</code></pre>
<p>On Windows, probably the easiest is probably to create a special shortcut icon which has added the flag given above (right-click on shortcut -&gt; properties -&gt; target).</p>
<p>On Mac OSX, you can do this with</p>
<pre><code>open /Applications/Google\ Chrome.app --args --allow-file-access-from-files
</code></pre>
<h4>Firefox</h4>
<ol>
<li>Go to <code>about:config</code>
</li>
<li>Find <code>security.fileuri.strict_origin_policy</code> parameter</li>
<li>Set it to <code>false</code>
</li>
</ol>
<hr>
<h3>Run local server</h3>
<p>The simplest probably is to use Python's built-in http server. </p>
<p>If you have <a href="http://python.org/">Python</a> installed, it should be enough to run this from a command line:</p>
<div class="highlight highlight-source-shell"><pre><span class="pl-c"><span class="pl-c">#</span> Python 2.x</span>
python -m SimpleHTTPServer</pre></div>
<div class="highlight highlight-source-shell"><pre><span class="pl-c"><span class="pl-c">#</span> Python 3.x</span>
python -m http.server</pre></div>
<p>This will serve files from the current directory at localhost under port 8000:</p>
<p>http://localhost:8000/</p>
<p>If you have Ruby installed, you can get the same result running this instead:</p>
<div class="highlight highlight-source-shell"><pre>ruby -r webrick -e <span class="pl-s"><span class="pl-pds">"</span>s = WEBrick::HTTPServer.new(:Port =&gt; 8000, :DocumentRoot =&gt; Dir.pwd); trap('INT') { s.shutdown }; s.start<span class="pl-pds">"</span></span></pre></div>
<p>PHP also has a built-in web server, starting with php 5.4.0:</p>
<div class="highlight highlight-source-shell"><pre>php -S localhost:8000</pre></div>
<p>Node.js has a simple HTTP server package. To install:</p>
<div class="highlight highlight-source-shell"><pre>npm install http-server -g</pre></div>
<p>To run:</p>
<div class="highlight highlight-source-shell"><pre>http-server <span class="pl-c1">.</span></pre></div>
<p>Other simple alternatives are <a href="http://stackoverflow.com/q/12905426/24874">discussed here</a> on Stack Overflow.</p>
<p>Of course, you can use any other regular full-fledged web server like <a href="http://www.apachefriends.org/en/xampp.html">Apache</a> or <a href="http://nginx.org/">nginx</a>.</p>
<p>Example with lighttpd, which is a very lightweight general purpose webserver (on MAC OSX):</p>
<ol>
<li>Install it via homebrew <code>brew install lighttpd</code>
</li>
<li>Create a configuration file called lighttpd.conf in the directory where you want to run your webserver. There is a sample in <a href="http://redmine.lighttpd.net/projects/lighttpd/wiki/TutorialConfiguration">this</a> page.</li>
<li>In the conf file, change the server.document-root with the directory you want to serve</li>
<li>Start it with <code>lighttpd -f lighttpd.conf</code>
</li>
<li>Navigate to http://localhost:3000/ and it will serve static files from the directory you chose.</li>
</ol> </body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册