File tree Expand file tree Collapse file tree
fixtures/mountDirectory/content/.hidden Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,7 +112,9 @@ export const createApp = (
112112 }
113113 next ( ) ;
114114 } ) ;
115- app . use ( '/api/markdown' , express . static ( directory ) ) ;
115+ // Default express.static ignores dot-segments, so /.hidden/file.md would
116+ // fall through to the SPA catch-all and return index.html as "markdown".
117+ app . use ( '/api/markdown' , express . static ( directory , { dotfiles : 'allow' } ) ) ;
116118
117119 // Catch-all route to serve index.html for any other requests
118120 app . get ( '*splat' , async ( req , res ) => {
Original file line number Diff line number Diff line change @@ -43,6 +43,14 @@ describe('Server E2E Tests', () => {
4343 expect ( res . text ) . toContain ( '# Hello E2E' ) ;
4444 } ) ;
4545
46+ it ( 'GET /api/markdown/.hidden/readme.md should return markdown from a dot-directory' , async ( ) => {
47+ const res = await request ( app ) . get ( '/api/markdown/.hidden/readme.md' ) ;
48+ expect ( res . statusCode ) . toEqual ( 200 ) ;
49+ expect ( res . headers [ 'content-type' ] ) . toMatch ( / m a r k d o w n | p l a i n | o c t e t - s t r e a m / ) ;
50+ expect ( res . text ) . toContain ( '# Hidden directory markdown' ) ;
51+ expect ( res . text ) . not . toContain ( '<title>mdts - Markdown file viewer</title>' ) ;
52+ } ) ;
53+
4654 it ( 'GET /api/outline should return the outline for a markdown file' , async ( ) => {
4755 const res = await request ( app ) . get ( '/api/outline?filePath=test.md' ) ;
4856 expect ( res . statusCode ) . toEqual ( 200 ) ;
Original file line number Diff line number Diff line change 1+ # Hidden directory markdown
2+
3+ This file lives under a dot-directory.
Original file line number Diff line number Diff line change @@ -79,6 +79,11 @@ describe('server.ts unit tests', () => {
7979 expect ( app . use ) . toHaveBeenCalledWith ( expect . any ( Function ) ) ; // for express.static
8080 } ) ;
8181
82+ it ( 'should allow serving markdown files from dot-directories' , ( ) => {
83+ const express = jest . requireMock ( 'express' ) ;
84+ expect ( express . static ) . toHaveBeenCalledWith ( '/mock/directory' , { dotfiles : 'allow' } ) ;
85+ } ) ;
86+
8287 it ( 'should define /api/filetree and /api/outline routes' , ( ) => {
8388 expect ( app . use ) . toHaveBeenCalledWith ( '/api/filetree' , expect . objectContaining ( { get : expect . any ( Function ) } ) ) ;
8489 expect ( app . use ) . toHaveBeenCalledWith ( '/api/outline' , expect . objectContaining ( { get : expect . any ( Function ) } ) ) ;
You can’t perform that action at this time.
0 commit comments