dapperdox icon indicating copy to clipboard operation
dapperdox copied to clipboard

Can't load Javascripts in localhost

Open vverrastro opened this issue 7 years ago • 6 comments

Hi all, I'm testing and configuring a documentation with dapperdox. In static directory I have:

css/style.css -> Load OK images/myfavicon.png -> Load OK javascripts/jquery.min.js - explorer.js etc... -> NOT Load [info] GET /javascript/explorer.js (404, 1.0022ms) - With debug same error in browser

All others javascripts into directories exemple doesn't work. Why I find my images but javascript no? Thanks all for support Vito

vverrastro avatar Apr 20 '17 16:04 vverrastro

A few questions.

  1. What OS are you using?
  2. Did you build yourself, or download a binary release?
  3. If built yourself, are you building from master, and what is the latest commit ref? If a binary release, what version?

To help, I have just put together the following simple test, which should work as documented. I used a fresh build from the master branch (commit 7fc1e) on Mac OS X. Can you do the same test and compare the results?

I note that you're not getting any javascript loading, including explorer.js.... strange! Chris

Static assets test

I created a test local assets directory:

$ cd $HOME
$ mkdir -p dapperdox_test/assets/static/images
$ mkdir -p dapperdox_test/assets/static/javascript

I then created the following files:

dapperdox_test/assets/static/images/fred.png
dapperdox_test/assets/static/javascript/hello.js

Having done that, I ran DapperDox with the following configuration, in my dapperdox_demo directory. Note that <DAPPERDOX_DIRECTORY> should be changed to point to your dapperdox directory.:

<DAPPERDOX_DIRECTORY>/dapperdox \
    -default-assets-dir=<DAPPERDOX_DIRECTORY>/assets \
    -spec-dir=<DAPPERDOX_DIRECTORY>/examples/specifications/petstore \
    -bind-addr=0.0.0.0:3123 \
    -site-url=http://localhost:3123 \
    -log-level=debug \
    -assets-dir=./assets

Note that I have turned debug on

I then get the following log output (here just showing the interesting bits):

2017/04/20 18:04:06 - Scanning directory /Users/csmith1/dapperdox_test/assets/static
2017/04/20 18:04:06   + Import assets/static/images/fred.png
2017/04/20 18:04:06   + Import assets/static/javascript/hello.js

2017/04/20 18:04:06 registering not found handler in static package
2017/04/20 18:04:06 registering static content handlers for static package
2017/04/20 18:04:06 registering handler for static asset: /css/xcode.css
2017/04/20 18:04:06 registering handler for static asset: /js/explorer.js
2017/04/20 18:04:06 registering handler for static asset: /js/jquery.wiggle.min.js
2017/04/20 18:04:06 registering handler for static asset: /javascript/hello.js
2017/04/20 18:04:06 registering handler for static asset: /js/highlight.pack.js
2017/04/20 18:04:06 registering handler for static asset: /images/fred.png
2017/04/20 18:04:06 registering handler for static asset: /css/style.css
2017/04/20 18:04:06 registering handler for static asset: /js/FileSaver.js
2017/04/20 18:04:06 registering handler for static asset: /js/jquery-1.8.0.min.js
2017/04/20 18:04:06 registering handlers for home page
2017/04/20 18:04:06 listening on 0.0.0.0:3123 for unsecured connections

Notice that it has imported both files and shown us the URL it has registered for each.

I then fetch http://localhost:3123/images/fred.png from my browser, and http://localhost:3123/javascript/hello.js, both succeed and the DapperDox log shows:

2017/04/20 18:06:53 [tcuAxhxKQFDaFpLSjFbc] [info] GET /images/fred.png (200, 275.91µs)
2017/04/20 18:07:13 [XoEFfRsWxPLDnJObCsNV] [info] GET /javascript/hello.js (200, 95.276µs)

If you do the same, what do you get?

zxchris avatar Apr 20 '17 17:04 zxchris

Hi @zxchris,

  1. I'm using Windows 10 64bit
  2. I tried binary release: dapperdox-1.1.1.windows-amd64.zip and dapperdox-1.1.1.windows-x86.zip and building myself. Result is the same.

I tried your exemple:

C:\Users\verra\OneDrive\Documents\dapperdox-test

- dapperdox-test
          dapperdox-test\assets
                                             \static\images\red.png
                                              \static\css\style.css
                                               \static\javascript\custom.js
          dapperdox-test\examples\specifications\petstore\swagger.json
          dapperdox-test\dapperdox.exe
          dapperdox-test\run_example.bat

run_example.bat configuration

.\dapperdox ^
      -bind-addr=0.0.0.0:3123 ^
      -default-assets-dir=./assets ^
      -site-url=http://localhost:3123 ^
      -spec-dir=examples\specifications\petstore\ ^
      -log-level=debug ^
      -force-specification-list=false ^
      -theme=default 

This is the output

2017/04/21 11:50:14 - Scanning directory C:\Users\verra\OneDrive\Documents\dapperdox-test\assets\static
2017/04/21 11:50:14   + Import assets/static/css/style.css
2017/04/21 11:50:14   + Import assets/static/css/style.keep.css
2017/04/21 11:50:14   + Import assets/static/images/red.png
2017/04/21 11:50:14   + Import assets/static/javascript/custom.js
ect...
ect...
2017/04/21 11:50:14 Registering guides
2017/04/21 11:50:14 - Specification guides for 'Swagger Petstore'
2017/04/21 11:50:14 - Root guides
2017/04/21 11:50:14
2017/04/21 11:50:14 registering not found handler in static package
2017/04/21 11:50:14 registering static content handlers for static package
2017/04/21 11:50:14 registering handler for static asset: /css/style.css
2017/04/21 11:50:14 registering handler for static asset: /images/red.png
2017/04/21 11:50:14 registering handler for static asset: /css/style.keep.css
2017/04/21 11:50:14 registering handlers for home page
2017/04/21 11:50:14 listening on 0.0.0.0:3123 for unsecured connections


2017/04/21 11:52:57 [LOpbUOpEdKupdOMeRVja] [info] GET /images/red.png (200, 4.0132ms)
2017/04/21 11:53:12 [RzLNTXYeUCWKsXbGyRAO] [info] GET /javascript/custom.js (404, 0s)

With other tests I have same result. Always problem with javascript. With package "getting started" too.

Let me ask you another question please. With dapperdox you can get the files for a static site? If I want integrate this site with another.

Thank you for support. Vito

vverrastro avatar Apr 21 '17 09:04 vverrastro

Okay, thanks for the update!

This looks like a windows file path problem (being different to Mac, Linux etc...) and maybe it's not quite right ;-)

We are investigating. Back soon.

zxchris avatar Apr 21 '17 14:04 zxchris

Current issue

We are struggling to reproduce your problem. Can you zip up your dapperdox_test directory and send it to us (including the run script)?

One thing to note, is that it looks like you are putting your own files in the DapperDox assets directory? You should not really be doing this. Instead have your own assets directory (pointed to by -assets) and point dapperdox at its assets with the -default-assets configuration. Have a look at my run script I used in my test above.

Help with fetching remote resources

With regard to fetching static files from another site:

You can just directly reference the remote resource in your asset, just like any other website:

<img src="http://dapperdox.io/imges/dapperdox_logo_circle_outline_120x120.png" />

Or, if you want everything to appear as though it came from the DapperDox service, you can use DapperDox's reverse-proxy configuration to do this.

For example, to fetch remote static content from http://dapperdox.io/ you configure a DapperDox remote proxy path, give it a stem (say /remote-static/) and point it to where you want that content fetched from.

-proxy-path=/remote-static/=http://dapperdox.io/

And thus, to request a resource from that remote site, you would reference them like this in your local assets:

<img src="/remote-static/images/dapperdox_logo_circle_outline_120x120.png" />

Or you could be more specific:

-proxy-path=/remote-images/=http://dapperdox.io/images/
<img src="/remote-images/dapperdox_logo_circle_outline_120x120.png" />

Lastly, if you want to use HTML files from another site as asset files in DapperDox, then you have to have those files locally, currently. You cannot fetch those file from a remote website (if DapperDox allowed this, you would also have to enable directory listing on your remote site, which would be unadvisable....). Our experience has been that images, JS and CSS are mainly the things that are directly re-usable, and can all be fetched by the webpage using the techniques above.

For HTML assets (say, headers, footer etc), we generally advise that such assets are built as a (git) repo that is shared by both the DapperDox site and the static site.

zxchris avatar Apr 25 '17 10:04 zxchris

I'm experiencing the same loading issues with the shipped JavaScript files. I've tested this on:

  • macOS with the latest Darwin release (1.1.1)
  • an Ubuntu 14.04 box with the latest amd64 release (1.1.1); with and without a simple Nginx reverse-proxy setup in front of it
  • an AWS EC2 instance with some Linux and the latest two amd64 releases (1.1.0 + 1.1.1); with the default Nginx setup provided by Beanstalk

On the first two machines, everything is working fine. Thus, I figured the Beanstalk Nginx configuration must do something weird. Is there any way one of those preset headers brings the DapperDox server to return 404s?

maximumstock avatar Aug 23 '17 13:08 maximumstock

Yep, having the same issue with an out-of-the-box install of the Windows version. Opening up F12 Developer Tools, I see a bunch of 404's on javascript files, including "jquery.wiggle.min.js". Additionally "Try It Out" doesn't work.