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.

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top