Вопрос

my st instance configured with

var mount = st({ 
  path: './app/',
  url: '/', // defaults to path option
  index: 'index.html',
  cache: {
    fd: none,
    content: none
  }
});

so when I send request to res/img/1.jpg it goes to ./app/res/img/1.jpg That's pretty much clear. But if have some requests to app/res/img/1.jpg then it redirect this requests to ./app/app/res/img/1.jpg and of course find nothing, because I have different file structure.

Is it possible to configure st or maybe add some custom code to skip path adding if it's already exist in URI? Or maybe it possible some way to add specific path which handles different, like some exclusions?

Это было полезно?

Решение

I don't know if it possible to do that with st directly, but you simply could add code to rewrite url if it met for some cases.

ad code like

var exceptions = { 
 'wrong_path':'right_path'
}

function rewriteUrl(req){
  if(exceptions[req.url]){
   req.url = exceptions[req.url];
  }
}

and then call that function before st method calling

http.createServer(function (req, res) {
  rewriteUrl(req);
  mount(req, res);
}).listen(1234);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top