-
Notifications
You must be signed in to change notification settings - Fork 835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No Multi Path Static File Mapper #2228
Comments
Triage: This feature / ask does not make sense without #187. Closing as dupe. |
Duplicate of #187 |
For first aid to my project. I provider a rough temp solution to this problem. May be usefull for other users.
public Task Invoke(HttpContext context)
{
if (context.GetEndpoint()?.RequestDelegate is null &&
IsGetOrHeadMethod(context.Request.Method) &&
MatchFile(context, out var matchFile))
{
context.Request.Path = matchFile;
}
return _next(context);
}
private bool MatchFile(HttpContext context, out PathString matchFile)
{
var path = context.Request.Path;
if (!(path.HasValue && path.Value!.EndsWith("/")))
{
path += new PathString("/");
}
var config = _configs.FirstOrDefault(it => it.RequestPath == path);
if (config == null)
{
matchFile = PathString.Empty;
return false;
}
var relativePath = path.ToString()[config.RequestPath.ToString().Length..];
var dictContents = config.FileProvider.GetDirectoryContents(relativePath);
if (dictContents.Exists)
{
for (int matchIndex = 0; matchIndex < config.Files.Count; matchIndex++)
{
var defaultFile = config.Files[matchIndex];
var file = config.FileProvider.GetFileInfo(relativePath + defaultFile);
if (file.Exists)
{
matchFile = path + defaultFile;
return true;
}
}
}
matchFile = PathString.Empty;
return false;
} |
Originally posted by @samsp-msft in #187 (comment)
I want to use yarp in some senaros like :
eg.
/app map to index.html under the folder
/app/index.html to index.html too.
The backend proxy is easy to config. But I've no idea for two static folder map ("/" and "/apps").
The text was updated successfully, but these errors were encountered: