Meteor public folder not working
Asked Answered
Y

3

24

I'm new to Meteor and I'm trying to understand how to serve static content - images, JS, etc.. I've followed the docs by creating the correct folder structure (which it doesn't really touch on) but making requests to this content just fails over to serving the main app page instead.

For instance - putting an image in "app_root"/public/image.png and making a request to localhost:3000/image.png just returns the main app page.

Any clue what I'm doing wrong here? Thanks!

Yippee answered 20/7, 2012 at 18:28 Comment(1)
After running "meteor", can you look inside app_root/.meteor/build/static/ and see if your image appears there? Also, what is the actual name of your file? Is it actually image.png?Gloucester
B
19

The setup you have described sounds correct to me. Media in public/ are served like

http://localhost:3000/myphoto.jpg

The todos example serves images from the public directory. Just back out of whatever project you're in and run: meteor create --example todos then cd into todos/ and run meteor. Then open:

http://localhost:3000/destroy.png 

The image you will see lives in public/.

Biphenyl answered 20/7, 2012 at 18:28 Comment(0)
P
16

Meteor public folder not working

Use ./public directory for serving static assets.

Given the following directory structure:

- server
- client
- public
  - css
    - bootstrap.css
  - images
  - js

You could serve the static assets by dropping 'public' from linked documents.

<link href='/css/bootstrap.css'>

More info here: Official Meteor Docs #FileStructure

Files in /public are served to the client as-is. Use this to store assets such as images. For example, if you have an image located at /public/background.png, you can include it in your HTML with or in your CSS with background-image: url(/background.png). Note that /public is not part of the image URL.

Paleolithic answered 7/5, 2014 at 16:44 Comment(2)
what happen to css folder, does that work under public ?Walczak
in this example, youd want to drop public from the urlPaleolithic
R
2

That same thing happened when I moved the project files in a folder and forget to move the directory .meteor.

Repulse answered 27/7, 2012 at 18:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.