0

I am learning D3 and I am trying to set up a local server on a mac machine to host a webpage. I follow these steps

  1. Set up the local server using: python -m SimpleHTTPServer 8888 &
  2. Access the index file using: http://localhost:8888

Here are the problems I am facing.

  • When I try step 2 I get the following messages on terminal

    127.0.0.1 - - [25/Aug/2014 12:14:52] "GET / HTTP/1.1" 200 -
    127.0.0.1 - - [25/Aug/2014 12:14:52] code 404, message File not found
    127.0.0.1 - - [25/Aug/2014 12:14:52] "GET /d3/d3.v3.js HTTP/1.1" 404 -
    127.0.0.1 - - [25/Aug/2014 12:14:53] code 404, message File not found
    127.0.0.1 - - [25/Aug/2014 12:14:53] "GET /favicon.ico HTTP/1.1" 404 -
    
  • When I open the index file directly it does not open via the local web server and instead opens with the following address "file://.../Users/d3_book/index.html" Here is the code (without the html tags) for my index file

    <head>
        <meta charset="utf-8">
        <title>D3 Page Template</title>
        <script type="text/javascript" src="../d3/d3.v3.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            // D3 code will go here
        </script>
    </body> 
    
Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
Plhu
  • 117
  • 1
  • 9

1 Answers1

1

You say your d3 files are in "../d3/d3.v3.js" but the server is looking for them in /d3/d3.v3.js. Perhaps that could be the source of the error?

The web server might not be able to access files outside of the directory that it was started in.

  • You are right. I figured it out myself just now. There were a couple of errors. The correct path is `/d3/d3.js` instead of `../d3/d3.v3.js`. I am still unable to open the webpage directly by clicking on it. I have to specify the path via the local host. Which I guess is fine for now. Though I wonder if there is an obvious solution that my novice brain is missing. – Plhu Aug 25 '14 at 20:11
  • 1
    Do you mean you can't open the `index.html` file by double clicking it? You won't be able to do that and have it run on the server, you'd have to go to `http://localhost:8080/index.html`. – Michael Slevin Aug 25 '14 at 20:24
  • Of course. D3 is an awesome framework, have fun with it. – Michael Slevin Aug 25 '14 at 21:29