3

I'm trying to set up Parse hosting (which is based on node.js) to handle certain URLs by returning a specific static file. This is to make it work with Ember.js history based routing (http://emberjs.com/guides/routing/specifying-the-location-api/).

So for example: I want all the following URLs to load the root index.html without doing a 301 redirect:

domain.com/search domain.com/about domain.com/some-other-route

This is easily doable in an Apache .htaccess rewrite rule. Is there something similar I can use with Parse hosting? Or do I have to write my own code that handles those URLs and return the file I want somehow?

Let me know if my description is not clear and I'll try to add more details.

Moe Salih
  • 723
  • 1
  • 7
  • 15
  • You should be careful. Many URLs loading the same page will lead to duplicate content and that's not what you want – Justin Iurman Jul 29 '14 at 15:57
  • @JustinIurman I understand that. But that's specifically what the Ember docs are saying: "Keep in mind that your server must serve the Ember app at all the routes defined here" from the above link. – Moe Salih Jul 29 '14 at 16:02

2 Answers2

1

Use Express on Parse and have it render your index.html as if it were an EJS view. Either copy your index.html to cloud/views/index.ejs or sym-link it to the same location.

// cloud/main.js
require('cloud/app.js');

Then

// cloud/app.js

var express = require('express');

var app = express();
app.set('views','cloud/views');
app.set('view engine', 'ejs');

app.get('/*', function(req, res) {
    res.render('index.ejs');
});

app.listen();

I'd been looking for an answer to this question FOREVER, and turns out the Google Group for Parse.com seems more active than Parsers on Stack Overflow. Found this answer here.

blisstdev
  • 633
  • 4
  • 13
  • In your code example, wouldn't GET '/*' interfere with loading css and js files that are in the public directory? or does the public folder have higher priority than express routes? – Moe Salih Oct 02 '15 at 17:54
  • Nevermind. I tested and it seems the public directory has priority. – Moe Salih Oct 02 '15 at 19:47
0

I have found this answer. You can change the filename. If filename=="search" then filename="index.html", and this way you get a different file. Link

Community
  • 1
  • 1
androbin
  • 1,622
  • 14
  • 31