question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with static app and LocalFileAdapter

See original GitHub issue

Bug report

Describe the bug

I have a keystone app with a StaticApp configured to serve files located on the public folder on the root of my project:

new StaticApp({ path: '/public', src: 'public' })

and a LocalFileAdapter configured to store files on a subdirectory of the static app path:

const fileAdapter = new LocalFileAdapter({
  src: 'public/uploads',
  path: '/public/uploads'
});

This setup works fine on development mode but in production mode when the app is built the contents of the root public folder are copied to dist/public and thats the folder served by the keystone server… so when a file is uploaded using the admin UI it goes through the LocalFileAdapter to the public folder on the root of my project so I get a 404 when I try to access the file using the public path URL because the file does not exist in dist/public.

To Reproduce

Explained above.

System information

  • OS: macOS and Linux
  • Browser: any

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bertezcommented, Mar 6, 2020

It’s the same… I understand the behavior of the Static App is correct and I finally set up the local file adapter to save the files in a different folder and set up nginx in production to serve that folder as static content.

While in development I use express.static:

module.exports = {
  keystone,
  apps,
  configureExpress: app => {
    app.set('trust proxy', 1);
    isDev && app.use('/uploads', express.static('uploads'));
  }
};

Maybe there is a better way but for the time being this works for me.

0reactions
HostenMarijncommented, Jan 12, 2021

Hey,

Does the file adapter throw weird error responses on your nginx server?

Mine goes like this when I try to upload an image (works fine on localhost/development): Screenshot 2021-01-12 at 11 27 57

And the image isn’t uploaded to the webserver. File permissions are 755 across the board…

Thanks for any feedback

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express-js can't GET my static files, why? - Stack Overflow
I have resolved the problem with following code: app.use('/img',express.static(path.join(__dirname, 'public/images'))); app.use('/js' ...
Read more >
Debugging issues with static files - PythonAnywhere help
Your static files mapping is not active yet. You may need to reload your web app. You've used a relative path instead of...
Read more >
Static files in ASP.NET Core | Microsoft Learn
Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default.
Read more >
problem serving static files in digital ocean app platform - Reddit
Hello Everyone, i created a simple project in django and i'm trying to deploy it on digital ocean with the app platform. i...
Read more >
How Do You Serve Static Files in Flask? - Sentry
But when you run your Flask app, the static files are not found and do not show up on your webpage. The problem...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found