jussi-kalliokoski / gulp-awspublish-router

A router for defining file-specific rules with gulp-awspublish

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reference to current file name?

Lingonmirakel opened this issue · comments

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 */}/`
    }
  }
}

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.