Skip to content
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

Dot files like .well-known files are not served with the node adapter #5813

Closed
1 task
hibnico opened this issue Jan 10, 2023 · 3 comments · Fixed by #5832
Closed
1 task

Dot files like .well-known files are not served with the node adapter #5813

hibnico opened this issue Jan 10, 2023 · 3 comments · Fixed by #5832
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@hibnico
Copy link

hibnico commented Jan 10, 2023

What version of astro are you using?

1.9.1

Are you using an SSR adapter? If so, which one?

Node

What package manager are you using?

npm

What operating system are you using?

Mac,Linux

Describe the Bug

We want our app to serve a file on the path /.well-known/apple-app-site-association. So I have put the file at that path public/.well-known/apple-app-site-association.

When running npm run dev, the file is being served, a curl http://127.0.0.1:3000/.well-known/apple-app-site-association returns a 200.

With a production build (npm run build), the file is not being served via node ./dist/server/entry.mjs. The same curl returns a 404. (node 16.19.0 on macos, docker image node:16-alpine on linux)

I can see that the .well-known folder is being properly copied by the build into dist/client/.well-known. But no file or directory starting with a dot is being served.

All that has been observed on our real project, on macos and linux.

I then tried to start a new astro project from scratch, on macos, basically just running:

  • npm create astro@latest
  • npm install @astrojs/node
  • create a file at public/.well-known/apple-app-site-association
  • configure astro with export default defineConfig({ output: "server", adapter: node({ mode: "standalone", }), });

In dev, it works, npm run dev and curl http://127.0.0.1:3000/.well-known/apple-app-site-association returns a 200.
With a build, it doesn't: npm run build and node ./dist/server/entry.mjs then curl http://127.0.0.1:3000/.well-known/apple-app-site-association returns a 404. But this time, I cannot see any .well-know directory in dist/client.

I would expect the node server to serve any file of the public folder, even the dot files.

Link to Minimal Reproducible Example

Participation

  • I am willing to submit a pull request for this issue.
@HiDeoo
Copy link
Member

HiDeoo commented Jan 10, 2023

I can see that the .well-known folder is being properly copied by the build into dist/client/.well-known.

I can repro the issue altho for me the .well-known directory is not copied to dist/client.

It looks like the issue can be pinpoint to 2 problems:

  1. During the build, when copying the public directory over, dot folders are ignored due to fast-glob not including dot folders by default:
const files = await glob('**/*', {
  cwd: fileURLToPath(fromFolder),
});

To include dot folders, the code should be:

const files = await glob('**/*', {
  cwd: fileURLToPath(fromFolder),
  dot: true,
});

I guess this should only be done when copying the public directory so potentially configurable through a new parameter to copyFiles(fromFolder: URL, toFolder: URL), e.g. copyFiles(fromFolder: URL, toFolder: URL, includeDotfiles = false).

  1. In the server, when responding to a request, send is configured to deny dotfiles:
const stream = send(req, encodeURI(pathname), {
  root: fileURLToPath(client),
  dotfiles: 'deny',
});

The dotfiles property should be changed to allow to properly serve dotfiles.

After testing locally both changes, a .well-known/apple-app-site-association in the public folder can properly be saved.

I could make a PR altho I'm not sure what is the desired behavior. The dotfiles: 'deny' configuration seems to have been written on purpose, so can we change it easily? Should this be configurable somehow?

@bluwy bluwy added the - P3: minor bug An edge case that only affects very specific usage (priority) label Jan 10, 2023
@bluwy
Copy link
Member

bluwy commented Jan 10, 2023

@HiDeoo thanks for digging this out! It looks like your proposed changes make sense to me. Re:

I could make a PR altho I'm not sure what is the desired behavior. The dotfiles: 'deny' configuration seems to have been written on purpose, so can we change it easily? Should this be configurable somehow?

I think we can make it allow if the pathname starts with /.well-known/, and deny otherwise.

@HiDeoo
Copy link
Member

HiDeoo commented Jan 10, 2023

@bluwy Ok, I'll setup a PR with the proposed changes and your suggestion 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants