0

I have an Angular Universal + Asp Net Core App.

I need to serve static file from a "virtual directory".

On ASP NET side I have:

app.UseFileServer(new FileServerOptions
        {
            FileProvider = new PhysicalFileProvider(Configuration["CDN"]),
            RequestPath = new PathString("/cdn"),
            EnableDirectoryBrowsing = false
        });

On Angular Universal side I have tried:

app.use(express.static('CDN'));

app.use('/CDN', express.static('C:\path\to\CDN'));

But none of these works, I got this error:

main-es2015.js:1 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'CDN/photot.jpg'
gidanmx2
  • 469
  • 1
  • 9
  • 24

1 Answers1

0

I solved changing server.ts;

app.get('*', (req, res) => {
if(req.url.indexOf('CDN/')>-1){
    res.sendFile(req.url,{ root: 'C:\\path\\to\\cdn' });
} else {
    res.render('index', { req });
}});
gidanmx2
  • 469
  • 1
  • 9
  • 24