jussi-kalliokoski / gulp-awspublish-router

A router for defining file-specific rules with gulp-awspublish
29 stars 7 forks source link

Reference to current file name? #20

Open Lingonmirakel opened 6 years ago

Lingonmirakel commented 6 years ago

Hi and thanks for this router!

I'm wondering if it’s possible to get a reference to the current file’s name somehow? I want to set up a redirect scheme and this would be my preferred solution, if at all possible:

routes: {
  …
  '^[^.]+$': {
    …
    headers: {
        'Website-Redirect-Location': `/${/* Here I’d like to be able to access the file’s name */}/`
    }
  }
}
jussi-kalliokoski commented 6 years ago

Hi! It's currently not possible. However, I'd be happy to accept PRs that implement this functionality. The simplest way to implement it would probably be to map the header values with something like this:

function templatizeHeaders(path, routeMatcher, headers) {
  const newHeaders = {};
  Object.keys(headers).forEach(header => {
    newHeaders[header] = path.replace(routeMatcher, headers[header]);
  });
  return newHeaders;
}

I don't currently have time to do this myself, but I'll help in any way I can if someone else picks this up.