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

Get the path to the static folder #8769

Closed
lcswillems opened this issue Sep 17, 2019 · 8 comments
Closed

Get the path to the static folder #8769

lcswillems opened this issue Sep 17, 2019 · 8 comments

Comments

@lcswillems
Copy link

lcswillems commented Sep 17, 2019

Feature request

Is your feature request related to a problem? Please describe.

I would like to get the path to the static folder.

Such a function / variable is built-in in other frameworks like Laravel: https://laravel.com/docs/6.x/helpers#method-public-path

What I tried

I tried to get it with __dirname or ./ or process.cwd(), it works but the command depends either on the location of the file containing it or the location where the script is executed.

Hence, this is not convenient, because I have to modify my command if I move my file or execute the script from another place. For example, my app works locally but not on production using Now.

@gurkerl83
Copy link
Contributor

This ability is also relevant for other plugins such as next-i18next. Here the static folder / in the future perhaps the public folder includes translation files which are required to load from a deployed, server near function.

Hopefully one of the main contributors can shine some light on that issue, thx.

@StarpTech
Copy link
Contributor

StarpTech commented Sep 29, 2019

I don't know if I understand your issue correctly. Files are served with the static directory as described here. You can just use /static/<any-file>.

@lcswillems
Copy link
Author

I would like to read the file using fs.readFileSync, not to get through http. As @gurkerl83 mention it, it is useful for internationalization and reading locales defined in the static folder.

@StarpTech
Copy link
Contributor

Then read the file relative to your next.js root project "static" is fixed.

@gurkerl83
Copy link
Contributor

It is probably related with this issue - #8251. A merge request exists #8334

@lcswillems
Copy link
Author

If I use a relative path, then if I move the file containing the code, I need to modify the code of the file for example. If my code is in a package, then the path is different, etc... This is not ideal from my point of view.

@Timer
Copy link
Member

Timer commented Oct 18, 2019

Duplicate of #8251 (comment)

@Timer Timer marked this as a duplicate of #8251 Oct 18, 2019
@Timer Timer closed this as completed Oct 18, 2019
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants