[英]How to mix hybrid (server-side and client-side rendering) in node/express and Backbone?
I'm new to node, and to stack overflow, so only answer if you're patient. 我是node的新手,并且是堆栈溢出的对象,所以只有耐心地回答。 I'm having a surprisingly hard time integrating code that currently exists in two different little node apps.
我在集成两个不同的小节点应用程序中当前存在的代码时遇到了令人惊讶的困难。 I have a hard time believing I'm the first person with this problem, but I haven't found a similar question or example ( eg This similar question is only theoretical)
我很难相信我是这个问题的第一人,但是我没有找到类似的问题或例子( 例如,这个类似的问题只是理论上的)
What I have: 我有的:
res.render()
. res.render()
将ejs视图传递给客户端。 It has routes /login
, /signup
, and /home
. /login
, /signup
和/home
路由。 It works great, and when a user is logged in or signed up, the /home
route serves them an ejs, node-rendered home page displaying their info. /home
路由为他们提供一个ejs(节点呈现的主页),显示其信息。 app.use(express.static(__dirname + "/../public"))
to serve the backbone, and some routes that send json to the backbone client. app.use(express.static(__dirname + "/../public"))
服务于骨干网,以及一些将json发送到骨干网客户端的路由。 It works fine, but only with a random user id. What I want: In App #1, I want a route, like 'home:uid'
to render the backbone app for the user with that uid. 我想要的是:在应用程序1中,我想要一条路由,例如
'home:uid'
以使用该uid为用户呈现主干应用程序。 But I want to do it without ripping out my lovely /login
and /signup
routes that serve server-side rendered views. 但我想做到这一点而又不破坏我提供服务器端渲染视图的可爱的
/login
和/signup
路由。
Finally my question: How can I have the flow the node routes switch, after login, from serving server-side rendered views to backbone? 最后是我的问题:登录后,节点路由如何从服务端渲染视图切换到骨干网? How do I make the user id (in the
req
object) available to the backbone app that I'm sending to the client? 如何使用户ID(在
req
对象中)可用于我发送给客户端的骨干应用程序? Can I bundle the public directory with a user id and send that bundle only on /home:uid
requests? 我可以将公共目录与用户ID捆绑在一起,并且仅在
/home:uid
请求上发送该捆绑包吗?
Things I've tried and could use more direction on: 我已经尝试过并且可以在以下方面使用更多指导的事情:
app.use(express.static(__dirname + "/../public"), {index: false})
seems useful, but I'd like an example of how to user express static with index set to false. app.use(express.static(__dirname + "/../public"), {index: false})
似乎有用,但是我想举一个如何在索引设置为false的情况下表达静态的示例。 res.sendFile()
. res.sendFile()
。 This is a standard way to respond with static files. Thanks for patience & help. 感谢您的耐心配合和帮助。
This post by Airbnb seems to say that mixing client-side and server-side rendering in node is a frontier; Airbnb的这篇文章似乎说,在节点中混合客户端和服务器端渲染是一个前沿。 node isn't set up to, in one app, switch from serving files templated on the backend to serving static files that render on the front-end end.
节点未设置为在一个应用程序中从在后端模板化的服务文件转换为在前端呈现的静态文件的服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.