Serving Static Files with FlowRouter

I’m having trouble getting my favicons to show in the meteor/webpack kickstart-flowrouter project.

In the root project folder, there’s a main.html file, which is where I put in all my <head> stuff. Typically, this is where I would place the following code:

<link rel="icon" type="image/png" href="http://www.example.com/assets/favicon-96x96.png" sizes="96x96" />

However, this requires me to receive the /assets/ route from FlowRouter and to serve the image being requested.

I found this issue on Github, and maybe I’m just dumb, but I don’t understand how I can make this work for my case in particular. That issue seems to be talking more about links regarding static files rather than simply serving the file itself. Either that or I’m completely off the mark. Thanks in advance.

I think you need to put it into the public directory. Create a directory inside that called assets and put your images inside that.

This is something Meteor does automatically.

1 Like

Ah thanks! I was over-complicating things. Thanks, that worked! All I did was create a /public folder in the root project directory. I don’t know why I didn’t think that would work.

But what if a user could have no access to a file? For example, he tries to open .pdf file and has access, so I need to show that in new tab, but if he does not, I need to show “You have no access” instead. That’s the problem with static routs: if u have an ID of a document, u can get access directly to a file, if server gives it from public folder… What would u suggest?

Not sure if this solution would fit your use case, but I’m currently using meteorhacks:picker and something like:

Picker.route('/view/pdf', function (params, request, response, next) {
  let pdfId = params.query.pdfId;
  // let buf = a generated pdf file, using webshot and buffer 
  response.setHeader('Content-Type', 'application/pdf');
  response.statusCode = 200;
  response.end(buf);
});

And the url looks like: http://www.yourdomain.com/view/pdf?pdfId=somerandomstring. You can put auth in the route, and do things like return a non-200 response, etc.

1 Like

thank you very much, i’m trying right now, but i got the problem: i need to set “X-Accel-Redirect” header. It is kinda res.writeHead(302, {“Location”: “/path/to”});, but not rly, would be nice to get some advice :slight_smile:

i made the topick here, plz follow the link to answer :3

Seeing that FlowRouter and Picker are abandoned with many PRs left un-merged, I decided to “restart” both.

Please see: FineRouter and FinePicker. Please submit PRs and ask for contributor roles to get more involved.