File serving configuration (resourceStoreUri, delimiter, generateId)
Router options (contentType, contentDisposition)
Express router ready to mount on an Express app
// Simple PDF server
const router = createFileServingRouter(
{ resourceStoreUri: 'file:///tmp/pdfs' },
{ contentType: 'application/pdf', contentDisposition: 'attachment' }
);
app.use('/files', router);
// Multi-format server with dynamic content type and custom delimiter
const router = createFileServingRouter(
{ resourceStoreUri: 'file:///tmp/exports', delimiter: '_' },
{
contentType: (filename) => {
if (filename.endsWith('.pdf')) return 'application/pdf';
if (filename.endsWith('.csv')) return 'text/csv';
if (filename.endsWith('.txt')) return 'text/plain';
return 'application/octet-stream';
},
contentDisposition: 'inline',
}
);
app.use('/exports', router);
Create an Express router for serving files from a resource store
Features: