spring-raining / pretty-autoindex

Show nginx autoindex more pretty!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Suggestion] "location" instead of two servers in nginx

idanyas opened this issue · comments

Instead of creating two different servers on different ports you can create one single server using "location". For example with these configs:

nginx:

server {

  listen               80;
  listen               [::]:80;

  server_name          example.com;

  location / {
    root    /smth/pretty-autoindex/dist;
  }

  location /json-index/ {
      alias            /smth/to/show;
      autoindex        on;
      autoindex_format json;

      # Enable your browser to access here.
      add_header  Access-Control-Allow-Origin "http://example.com";
      add_header  Access-Control-Allow-Methods "GET, POST, OPTIONS";
      add_header  Access-Control-Allow-Headers "Origin, Authorization, Accept";
      add_header  Access-Control-Allow-Credentials true;
  }
}

config.js:

var conf = {
      name: 'example.com',
      address: 'http://example.com/json-index',

      visibilityOptions: {
          size: {
              use: true,
              type: 'readable' //raw, readable, both
          },
          date: {
              use: true,
              type: 'moment' //raw, moment, both
          }
      }
};

I probably could have made some mistakes, but overall I did something like this and it works.