gpt4 book ai didi

meteor 流路由器放置/安全

转载 作者:行者123 更新时间:2023-12-01 15:34:44 25 4
gpt4 key购买 nike

我有一个关于 meteor 上的流路由器的问题。在 meteor 的新项目结构中,建议将所有文件保存在“导入文件夹”中,并导入到服务器文件夹或客户端文件夹中。在我看到使用流路由器的教程中,没有导入文件夹,其中包含 js 文件的路由文件夹就保存在项目文件夹下。这向我提出了几个问题。

  1. 流路由器代码在哪里运行?在客户端?在服务器上?在两者上?
  2. 如果它在两者上运行,我应该将它放在导入文件夹之外吗?
  3. 如果它在两个/仅在客户端上运行,这在安全方面意味着什么?说我不希望某个用户能够访问某个页面,所以在 flow-router action() 中我写了一段代码来防止人们到达我不希望他们访问的地方,他们不能改变这段代码在客户端绕过墙?
  4. 在 flow-router js 文件中引用用户时,我是使用 Meteor.userId() 还是 this.userId?
  5. 我在 if(Meteor.isClient) 中编写了三个函数,我从教程中复制了这些函数。这些功能是 Accounts.onLogin、Accounts.onLogout、FlowRouter.tringgers.enter。因为它们在客户端上,所以用户可以破解它们吗?

提前致谢!

最佳答案

  1. 来自 documentation :

Flow Router is a client side router and it does not have Server Side Routing capability. It has no plans to implement such features either.

所以Flow Router只在客户端运行,你应该把相关代码放在/imports/startup/client

  1. 参见 (1)。通常,您的所有代码都应放在 imports 目录中。

    Meteor ensures that any file in any directory named server/ will only be available on the server, and likewise for files in any directory named client/

因此,如果您想让客户端和服务器都可以访问某些代码,请不要将其放在任何名为/client 或/server 的子目录中。

  1. 虽然以前使用 Iron Router 时,身份验证是在路由器层完成的,但使用 Flow Router 时,您应该在模板/组件层中编写身份验证逻辑。根据 Flow Router 的创建者的说法,在 Flow Router action() 中编写代码来阻止用户访问页面并不是一个好的模式。阅读here示例和更多详细信息。

In server-rendered apps(in the PHP era), if there is an unauthorized access, we can redirect the user to a login page or some other page. In Meteor, or in any single-page app, we can simply show a login screen to the user instead of redirecting them to another page. Or else, we can simply say: "You are not allowed to view this page."

  1. 与 (3) 相同。您不应该在路由器层中引用用户。

  2. 在客户端上运行的任何代码都无法抵御恶意用户。

您可能会发现以下内容很有用:

关于 meteor 流路由器放置/安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38410024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com