-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include an optional restRoute config #6
Conversation
So that I may override in my own configs to point to my own main route. `/public` directory is often used as a grunt build directory so a possibly dev config route is useful.
So that I may override in my own configs to point to my own main route. `/public` directory is often used as a grunt build directory so a possibly dev config route is useful.
Where do you put your It's probably a bit more complicated than your PR because you could also use a |
I built the app using yeoman and the main front end files live under I am trying to find a solution at the moment and trying to understand all the routes in and out of each of the modules. The PR I sent was a quick fix to use the config path that I could override in my own config and defaulting to your |
Here is how it works. A user gets an email with a link pointing to See the AngularJS example router examples/angular/public/js/app.js#L24 and controller examples/angular/public/js/controllers.js#L69. |
I did think that was a way to do it but it seems silly to load the front end app to just make another http request when the original could hit the route directly via the email link. That was my thinking for the first pull request when I deleted the lines that added /rest to the routes in lockit-signup. Perhaps that your suggestion is the slightly cleaner and more modular within the lockit ecosystem and letting the responsibility of the developer to know what I'm doing by setting In that case would it be a good idea to let the config dictate the location of the The issue and complication still remains of course if the index.html doesn't exist and should be rendered via jade or similar (handlebars in my case). But I think that is a bit more involved at the moment and requires more work than a simple config addition. Hope this helps and thanks for the clarification. |
Thanks a lot for all the detailed comments! Mixing server-side routing and client-side routing is not a good idea. It will get very confusing. I'll implement a solution where everybody is able to set the starting point of their SPA manually without too much hassle. |
Sorry for the long reply! But I just had another thought, the problem I have at the moment is that you use |
This gets the benefit of using express engine so we can point `config.restIndex` to a handlebars or jade file. Other option could include passing a config to res.render from another config option (such as layout: false or locals: { "what": "ever" })
That's what I tried to answer with my comment above. Soon you'll be able to send an HTML file via |
eek, i think my patch is patching itself! |
Hi Mirco, How is it going to implement a solution that allows users to render a starting page when |
Soon, and with your other fixes I'll release a new version. Thanks for all your help! |
Thanks for the update. I really think it an improvement but can I ask that Sorry to be a pain, its because I really like the whole idea of lockit and Closed #6 #6 via Reply to this email directly or view it on |
hah I'm so used to Jade that I forgot about other template engines. Thanks for the hint! How about this? // anything that doesn't end with .html should be render()ed
if (!/.+\.html$/.test(config.restIndexPage)) return res.render(config.restIndexPage);
// for .html files use sendfile()
res.sendfile(path.join(__parentDir, config.restIndexPage)); |
I like it! Thanks so much.
|
Thought about the issue a bit more. The problem is that a user could actually have Getting all the required info just from exports.rest = {
// render views or send JSON for single page apps
enabled: false,
// set starting page for single page app
index: 'public/index.html',
// use view engine (render()) or send static file (sendfile())
useViewEngine: false
} That's probably the most flexible solution. |
That's a good point that I also didn't think about. I use handlebars Talking of separating some options into another object, I had to make some Thanks.
|
Check out the just released version 0.8.0. It should solve both problems. Here is the changelog. |
I'd like to reopen this issue and make a proposal. I'm using lockit in a SPA using Ember.js. Routing in Ember is done in the hash part of the URL. So, I want to forward "/signup/a-token" to my frontend with an URL like "index.html#/signup/a-token". Forwarding via sendfile() does not feel suitable for my use case. For the SPA case, I'd like to have a custom hook, where I can forward to client routes in a non restricted, flexible way. I would prefer something like this for the registered routes: router.get(route, function(req, res) {
// check if user would like to render a file or use static html
if (config.rest.useViewEngine) {
res.render(config.rest.index, {
basedir: req.app.get('views')
});
}
// PROPOSAL START
else if (config.rest.customRouter)
{
config.rest.customRouter({
"req": req,
"res": res,
"route": route
});
}
// PROPOSAL END
else {
res.sendfile(path.join(__parentDir, config.rest.index));
}
}); Then I would have full control over all routing to the client by catching this hook: exports.rest = {
customRouter: function(p)
{
if (p.route.match(/^\/signup/))
{
p.res.redirect('/index.html#/signup/' + p.req.params.token);
}
},
useViewEngine: false
}; I think this would be more flexible and suitable for different use cases in different client frameworks. What do you think? Or am I misunderstanding the way of forwarding requests to the client? |
Hash based routing was hack to make SPAs work in the past. Nowadays modern browsers support the history api. Edit your Ember app and set App.Router.reopen({
location: 'history'
}); This removes the hash from the URL and everything should work as expected. |
So that I may override in my own configs to point to my own main route.
/public
directory is often used as a grunt build directory so a possibly dev config route is useful.