Closed valeriob closed 6 years ago
I typically serve static content from wwwroot. If I wanted to keep it in a feature folder organizationally, I would use a build task to copy the files into wwwroot, I think. For apps with significant client complexity (e.g. large Angular SPA), you're likely going to have an entire app folder with its own feature folders representing client features anyway, located in wwwroot.
Thanks @ardalis Have you done features folder in production with static files or it's just an idea ?
I haven't, honestly. But I am working with several clients building Angular SPAs and we're definitely using essentially feature folders within the Angular clients.
So basically you are using features folders concept to organize angular client code, correct ? But from aspnet core point of view it's still a spa, isn't it ?
That's right. I only mention it because in my experience I'm seeing parallel sets of folder structures on the server and client side. There may be some overlap, but often the client side has different file needs than the server side does, so it makes sense to me to not try to organize client files into server-side feature folders.
At the end of the day, they're really different apps (client vs. server) and could be organized into completely different projects, etc. if you wanted. For simpler (e.g. non-SPA) apps, it might make sense to keep the files in the server-side feature folders (and probably copy them into wwwroot), but that's not the first approach I would try.
Also realize that wwwroot itself is a security feature, because it ensures that files in the rest of your project folder are not at risk of download. If you start adding your own way for requests to reach non-wwwroot folders, you're potentially opening up security risks (like, an attacker might be able to use your feature to access appsettings.json or something else they shouldn't be able to get). Just be careful of that. That's one reason I would prefer to copy into wwwroot rather than giving requests access outside of it.
Thanks !
I think a feature folder is not complete with some static content, how do you serve it without copying to wwwroot ? I'm following this approach https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?tabs=aspnetcore2x#serve-static-files
app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "MyStaticFiles")), RequestPath = "/StaticFiles" });
But it only works if the file system path starts with a different char than the request path or it will not allow to have any routing parameter in the request.