Serving an "index.html" file in public/ when using MeteorJS and Iron Router?
Asked Answered
B

2

6

I want to serve a static HTML file from MeteorJS's public folder (as is possible with Rails and Express). The reason I'm doing this is because I have one template for the dynamic "admin" part of my webapp and another for the sales-y "frontend" part of the app.

I don't want this file to be wrapped in a Meteor template as suggested in this answer as it will automatically bring in the minified CSS, etc... that the dynamic pages use.

Is there a way I can setup the public folder (and all its subfolders) so that it serves index.html? This way http://app.com/ will load public/index.html?

Blastocyst answered 26/5, 2014 at 13:44 Comment(0)
K
8

You could use the private folder instead and then use Assets.getText to load the contents of the file, then serve it with a server-side router from iron-router.

So off the top of my head the code would look something like this:

if (Meteor.isServer) {
  Router.map(function() {
    this.route('serverRoute', {
      path: '/',
      where: 'server',
      action: function() {
        var contents = Assets.getText('index.html');
        this.response.end(contents);
      }
    });
  });
}
Karisa answered 26/5, 2014 at 13:59 Comment(3)
this.response.end(contents); to end the connection.Eleni
Hi Rahul, this is working great but not for server generated files. For example, in the /private folder, there are test1.html and test2.html. When I mup deploy to Digital Ocean server, test1.html and test2.html are working great! However, when I generated test3.html into the same folder as test1.html and test2.html, it just showed "Server error." How to make test3.html working? Thanks!Matilda
Hard to help without seeing your code. Please ask a separate question.Karisa
B
0

this is what I put in bootstrap.js

Router.route('/', {
  where: 'server'
}).get(function() {
  var contents;
  contents = Assets.getText('index.html');
  return this.response.end(contents);
});
Baez answered 21/6, 2016 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.