Document how to run examples in github repo

Document how to run examples in github repo

tacman1123tacman1123 Posts: 168Questions: 39Answers: 1

I'd like to run the examples locally, but am not sure how to do so.

git clone https://github.com/DataTables/DataTablesSrc
cd DataTablesSrc
cd build
./make.sh examples
./make.sh build
cd ../built/examples
php -S localhost:8300

While the index page works fine, none of the examples work:

http://localhost:8300/basic_init/zero_configuration.html

because it's looking for code in src="../../media/js/jquery.dataTables.js", which doesn't exist.

I feel like I'm missing something obvious, but I'm stuck. I've tried starting the server in different directories, but I can't even find the /media directory -- how is that created?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    Hi,

    It looks like you are 99% of the way there. However, on line 6 do:

    cd ../built/DataTables
    

    Then start the server from there and it should work.

    Its a bit weird I know - sorry! I really need to tidy that up and fully document it sometime. Its legacy stuff that has just built up over the years and it is now time to pay the tech debt back...

    Allan

  • tacman1123tacman1123 Posts: 168Questions: 39Answers: 1

    Hmm, that doesn't make sense to me. /built/Datatables doesn't have an index.html file, so opening localhost gives a 404:

    ~/g/tacman/DataTablesSrc/built/DataTables$ php -S localhost:8300
    [Fri Mar 17 06:13:15 2023] PHP 8.2.3 Development Server (http://localhost:8300) started

    Requesting examples doesn't load the css:

    http://localhost:8300/examples

    tac@tac-desktop1:~/g/tacman/DataTablesSrc/built/DataTables/examples$ php -S localhost:8300
    [Fri Mar 17 06:18:27 2023] PHP 8.2.3 Development Server (http://localhost:8300) started
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38774 Accepted
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38774 [200]: GET /
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38774 Closing
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38786 Accepted
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38788 Accepted
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38802 Accepted
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38786 [200]: GET /resources/syntax/shCore.css
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38810 Accepted
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38786 Closing
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38788 [200]: GET /resources/demo.css
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38788 Closing
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38802 [200]: GET /resources/syntax/shCore.js
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38802 Closing
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38810 [200]: GET /resources/demo.js
    [Fri Mar 17 06:18:37 2023] 127.0.0.1:38810 Closing
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38824 Accepted
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38824 [200]: GET /basic_init/zero_configuration.html
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38824 Closing
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38838 Accepted
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38846 Accepted
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38852 Accepted
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38868 Accepted
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38870 Accepted
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38876 Accepted
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38838 [404]: GET /media/css/jquery.dataTables.css - No such file or directory
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38838 Closing
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38846 [200]: GET /resources/syntax/shCore.css
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38846 Closing
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38852 [200]: GET /resources/demo.css
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38852 Closing
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38868 [404]: GET /media/js/jquery.dataTables.js - No such file or directory
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38868 Closing
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38870 [200]: GET /resources/syntax/shCore.js
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38876 [200]: GET /resources/demo.js
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38870 Closing
    [Fri Mar 17 06:18:42 2023] 127.0.0.1:38876 Closing
    [Fri Mar 17 06:18:44 2023] 127.0.0.1:38878 Accepted

    And switching to the ../built/DataTables/examples directory doesn't load the JS

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    /built/Datatables doesn't have an index.html file, so opening localhost gives a 404:

    You need to go to:

    localhost/examples
    

    Allan

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    Sorry - I've just seen that you used http://localhost:8300/examples.

    The example CSS should be at:

    http://localhost/examples/resources/demo.css
    
  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin
    Answer ✓

    I've just worked out what is going on...

    Load:

    http://localhost:8300/examples/
    

    That trailing slash turns out to be really important.

    Nginx (which we use in our development VMs for the examples) will automatically redirect a directory to have a / on it. The PHP built in server does not. That is important as our examples resolve URLs on a relative basis, hence the issues you were seeing.

    I found this PHP issue and this following one which basically say that this is a bug in the PHP built in server.

    Allan

Sign In or Register to comment.