-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Writing an application builder extension method to enable serving fil…
…es from node_modules
- Loading branch information
Showing
6 changed files
with
54 additions
and
23 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
OdeToFoodRider/OdeToFoodRider/Middleware/ApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.IO; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.FileProviders; | ||
|
||
namespace OdeToFoodRider.Middleware | ||
{ | ||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static IApplicationBuilder UseNodeModules(this IApplicationBuilder app, string root) | ||
{ | ||
var path = Path.Combine(root, "node_modules"); | ||
var fileProvider = new PhysicalFileProvider(path); | ||
|
||
var options = new StaticFileOptions(); | ||
options.RequestPath = "/node_modules"; | ||
options.FileProvider = fileProvider; | ||
app.UseStaticFiles(options); | ||
|
||
return app; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
OdeToFoodVisualStudio/OdeToFoodVisualStudio/Middleware/ApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Microsoft.Extensions.FileProviders; | ||
using System.IO; | ||
|
||
namespace Microsoft.AspNetCore.Builder | ||
{ | ||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static IApplicationBuilder UseNodeModules(this IApplicationBuilder app, string root) | ||
{ | ||
var path = Path.Combine(root, "node_modules"); | ||
var fileProvider = new PhysicalFileProvider(path); | ||
|
||
var options = new StaticFileOptions(); | ||
options.RequestPath = "/node_modules"; | ||
options.FileProvider = fileProvider; | ||
app.UseStaticFiles(options); | ||
|
||
return app; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters