-
-
Notifications
You must be signed in to change notification settings - Fork 110
feat: make root optional when serve is false #460 #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1000621
1e4db33
bcbeb56
0f6bb37
47a3de4
7616ffc
b67309e
8c39b1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>test file</title> | ||
| </head> | ||
| <body> | ||
| <h1>hello fastify</h1> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||
| 'use strict' | ||||||
|
|
||||||
| const path = require('node:path') | ||||||
| const assert = require('node:assert') | ||||||
| const { test } = require('node:test') | ||||||
| const Fastify = require('fastify') | ||||||
| const fastifyStatic = require('../index.js') | ||||||
|
|
||||||
| test('should not serve static files when serve is false', async t => { | ||||||
| const fastify = Fastify() | ||||||
| fastify.register(fastifyStatic, { | ||||||
| serve: false | ||||||
| }) | ||||||
|
|
||||||
| t.after(() => fastify.close()) | ||||||
| await fastify.listen({ port: 0 }) | ||||||
| fastify.server.unref() | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| const res = await fetch('http://localhost:' + fastify.server.address().port + '/public/example.html') | ||||||
| assert.strictEqual(res.status, 404) | ||||||
| }) | ||||||
|
|
||||||
| test('should serve static files when serve is true', async t => { | ||||||
| const fastify = Fastify() | ||||||
| fastify.register(fastifyStatic, { | ||||||
| root: path.join(__dirname, 'root'), | ||||||
| prefix: '/public/' | ||||||
| }) | ||||||
|
|
||||||
| t.after(() => fastify.close()) | ||||||
| await fastify.listen({ port: 0 }) | ||||||
| fastify.server.unref() | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| const res = await fetch('http://localhost:' + fastify.server.address().port + '/public/example.html') | ||||||
| assert.strictEqual(res.status, 200) | ||||||
|
|
||||||
| const content = await res.text() | ||||||
| assert.ok(content.includes('hello'), 'File content should contain "hello"') | ||||||
| }) | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,7 +85,7 @@ declare namespace fastifyStatic { | |
| } | ||
|
|
||
| export interface FastifyStaticOptions extends SendOptions { | ||
| root: string | string[] | URL | URL[]; | ||
| root?: string | string[] | URL | URL[]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Boring to write, but we need something like: |
||
| prefix?: string; | ||
| prefixAvoidTrailingSlash?: boolean; | ||
| serve?: boolean; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dipali127
Why should
normalizeRootalso be skipped?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this scenario we are not using root if I'm not wrong