3

I'm surprised I can't google my answer here... it seems no one else is having the issue.

When you run the meteor service the js, html, etc. is packaged in the .meteor/local/build folder, but it appears to exclude stuff that isn't js or html. I have a folder called "magicsets" and one called "magicimgs" and neither are in the /local/build folder. This is obviously why, when i attempt to use fs to readfile, it fails to find the file "magicsets/M14.json"

I tried putting the magicsets folder into a folder named "private", but that didn't accomplish anything.

How do I make files accessible locally to my server via FS and how do I make files accessible publically to my server via raw urls?

I'm sure I'm missing something very simple, because there are lots of more complicated questions and answers on SO, yet there is no answer for this. Thanks.

4

3 回答 3

17

Meteor 0.6.5 which was released yesterday has a new feature which helps loads with this.

Make a directory called /private which you can access with the new Assets.getText or Assets.getBinary functions.

The stuff in the /private directory will then be bundled up into a directory called assets in /program/server/assets and it will not be accessible to the web & you wouldn't need to worry about using fs either. You could just use Assets.getText instead

To make a publicly accessible file put it in /public. So if you had a.jpg at /public/a.jpg it would be accessible at http://yourdomain.com/a.jpg

于 2013-08-15T08:19:50.863 回答
1

If you want text files to be available to the webserver i.e. the server that defaults to port 3000, create a folder called public in the root of the project/app directory. drop your folder and files there. You would then be able to access them as http://localhost:3000/magicsets/M14.json

update: it looks like can override the bundler, but it does require changing some of the core code there's no .meteorignore file yet. check this SO answer out: https://stackoverflow.com/a/16742853/105282

于 2013-08-15T08:11:07.787 回答
1

To serve a directory of files publicly independent of what Meteor is doing, you can use the following approach. I do this, for example, when I need to link an entire (Javascript) git repo into my Meteor app so I can work on a checked out version of the library.

The following works for 0.6.5. It basically servers up a checked out folder of OpenLayers in /lib:

connect = Npm.require('connect')

RoutePolicy.declare('/lib', 'network')

WebApp.connectHandlers
  .use(connect.bodyParser())
  .use('/lib', connect.static("/home/mao/projects/openlayers/lib"))

For more information, see https://github.com/meteor/meteor/issues/1229.

于 2013-08-16T00:32:12.493 回答