izissise / nginx-explorer

File explorer in javascript, file come from nginx autoindex
MIT License
10 stars 3 forks source link

Activate json listing with an url param #19

Open izissise opened 4 years ago

izissise commented 4 years ago

Some software prefer html listing (eg: kodi), it should be possible to ask for html listing with an url param

Failed try with nginx conf

server {
    listen 80;

    root /home/user/downloads;
    #location for json requests
    location ^~ /files/ {
        #PathOnYourHardDrive Last slash is important
        alias /home/user/downloads/;

        # Random id so nginx doesn't serve random html files
        index aaaaaaaaaaaaaaaaaa;
        autoindex on;
        set $index_format "json";
        if ( $arg_html = "1" ) { set $index_format "html"; }
        autoindex_format $index_format;
        autoindex_exact_size on;

        sendfile           on;
        sendfile_max_chunk 2m;
        tcp_nopush         on;
        tcp_nodelay        on;
        keepalive_timeout  65;

        # error_page 418 = @htmllisting;
        # if ( $arg_html = "1" ) { return 418; }
    }

    # location @htmllisting {
    #     alias /;
    #     autoindex on;
    #     autoindex_format html;
    #     autoindex_exact_size on;
    #
    #     sendfile           on;
    #     sendfile_max_chunk 2m;
    #     tcp_nopush         on;
    #     tcp_nodelay        on;
    #     keepalive_timeout  65;
    # }

    location / {
        root /var/www/files/;
        # Try files so nginx serves the root index for all paths
        try_files $uri $uri/ /index.html;

        sendfile           on;
        sendfile_max_chunk 2m;
        tcp_nopush         on;
        tcp_nodelay        on;
        keepalive_timeout  65;
    }
}
izissise commented 2 days ago

Js code could support both