Skip to content

Commit e290764

Browse files
re-fcursoragent
andcommitted
fix: serve markdown files inside dot-directories
express.static ignores dot-segments by default, so /api/markdown/.hidden/file.md fell through to the SPA catch-all and returned index.html as the preview. Co-authored-by: Cursor <[email protected]>
1 parent 654eeb1 commit e290764

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/server/server.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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) => {

‎test/e2e/server.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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(/markdown|plain|octet-stream/);
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);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Hidden directory markdown
2+
3+
This file lives under a dot-directory.

‎test/unit/server/server.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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) }));

0 commit comments

Comments
 (0)