简体   繁体   English

快速 JS 路由

[英]Express JS Routes

Beginner question here.初学者问题在这里。 I'm wanting to build an app that will be an intranet of sorts for a 70 unit restaurant chain.我想构建一个应用程序,该应用程序将成为 70 家连锁餐厅的内部网。 What I'm needing is for each physical restaurant location to see data posted to a MongoDB DB and show on a page in the store within a screen hanging on the wall.我需要的是让每个实体餐厅位置查看发布到 MongoDB 数据库的数据,并显示在商店页面上挂在墙上的屏幕上。 This data will be specific to each location such as announcements, catering orders that need to be filled by that store, etc... my question is, how do I create routes so that each individual store will see only their data without having to create 70 different routes or use authentication to utilize user IDs?这些数据将特定于每个位置,例如公告、需要由该商店填写的餐饮订单等......我的问题是,我如何创建路线,以便每个单独的商店只能看到他们的数据而无需创建70 条不同的路由还是使用身份验证来利用用户 ID?

Trying to avoid user logins and:试图避免用户登录和:

“/store1” “/store2” “/store3” Etc... “/store1” “/store2” “/store3” 等等...

Seems like I could query a site ID or something like that好像我可以查询站点 ID 或类似的东西

Hope this make since.希望这使自。

If you're talking about one centrally located server that is accessed by all 70 restaurants and you want to have the same routes for all, then you need to decipher some other clue from the request to figure out which restaurant it is that is making the request.如果您正在谈论所有 70 家餐厅都可以访问的一个位于中心的服务器,并且您希望所有餐厅都拥有相同的路线,那么您需要从请求中破译一些其他线索,以确定是哪家餐厅正在制作要求。

Since you have nixed authentication, I will assume that there are no security concerns here - that this is on an intranet only accessible by restaurant employees.由于您已取消身份验证,我将假设这里没有安全问题 - 这是在只能由餐厅员工访问的内部网上。

So, here are the clues you could get from any given request to decide which restaurant's data to show:因此,以下是您可以从任何给定请求中获得的线索,以决定要显示哪个餐厅的数据:

  1. Cookie that contains desired restaurant ID.包含所需餐厅 ID 的 Cookie。
  2. Query parameter that contains desired restaurant ID.包含所需餐厅 ID 的查询参数。
  3. IP address of request to discern which restaurant the request is coming from.请求的 IP 地址,以识别请求来自哪个餐厅。
  4. Separate sub-domain for each restaurant (all pointing to the same host).每个餐厅的单独子域(都指向同一主机)。

Here's more info on each option:以下是有关每个选项的更多信息:

Cookie曲奇饼

In this implementation, if a client arrives with no cookie set for the restaurant ID, then you take them to an opening page where they select which restaurant they want to see the data for and you ask the user to manually select the desired restaurant.在这个实现中,如果客户到达时没有为餐厅 ID 设置 cookie,那么您将他们带到一个打开页面,在那里他们选择他们想要查看的餐厅的数据,然后您要求用户手动选择所需的餐厅。 Then, you set a long lasting cookie in that browser and from then on (as long as the cookie is not removed), your server can default to showing them info only for their restaurant.然后,您在该浏览器中设置一个持久的 cookie,从那时起(只要 cookie 没有被删除),您的服务器可以默认只显示他们餐厅的信息。

Query Parameter查询参数

In this implementation, you use some initial restaurant specification like in the cookie option and then you generate pages where all the links have a query parameter specified in them that lists the restaurant ID (likely using a template system).在此实现中,您使用一些初始餐厅规范,如 cookie 选项,然后生成页面,其中所有链接都指定了一个查询参数,其中列出了餐厅 ID(可能使用模板系统)。 This is generally not favored these days over a plain cookie system.如今,与普通的 cookie 系统相比,这通常不受青睐。

IP address IP地址

If all your restaurants have their own sub-network (presumably some sort of broadband connection connecting to a central server over some sort of private connection, then you could perhaps build a small table of restaurant source IP addresses so you could identify which restaurant was making the request purely by the IP address of the request. This may or may not be feasible depending upon your network topology. This would be much more automatic than any of the other options.如果您所有的餐厅都有自己的子网(大概是某种宽带连接通过某种专用连接连接到中央服务器,那么您也许可以构建一个小餐厅源 IP 地址表,以便您可以识别哪个餐厅正在制作请求完全由请求的 IP 地址决定。这可能可行,也可能不可行,具体取决于您的网络拓扑。这将比任何其他选项更自动。

Separate sub-domain单独的子域

This would work somewhat like the cookie-based option, but instead of setting a cookie, once the desired restaurant was selected, you would redirect to a subdomain specific to that restaurant.这有点像基于 cookie 的选项,但不是设置 cookie,一旦选择了所需的餐厅,您将重定向到特定于该餐厅的子域。 All sub-domains would still point to the same host, but the host could identify the desired restaurant from the sub-domain making the request.所有子域仍将指向同一主机,但主机可以从发出请求的子域中识别所需的餐厅。 Similar to the query parameter option, you'd some template system on the server side to rewrite all links to include the proper sub-domain so you'd stay on the same sub-domain as you navigate.与查询参数选项类似,您需要在服务器端使用一些模板系统来重写所有链接以包含正确的子域,以便您在导航时保持在同一个子域中。


Of all of these options, the IP address scheme is the only one that would be completely automatic, but may or may not be feasible depending upon your network topology.在所有这些选项中,IP 地址方案是唯一一种完全自动的方案,但根据您的网络拓扑结构可能可行,也可能不可行。 Of the other choices, the cookie is the most straightforward to implement because the page links themselves don't have to be rewritten.在其他选择中,cookie 是最容易实现的,因为页面链接本身不必重写。


Enterprise Configuration企业配置

In an enterprise scenario where you "manage" any browser that is approved for use, you may also be able to pre-configure the browser in each restaurant to automatically provide some identification (either a custom header or a cookie) and your server could use that identification info to determine which restaurant was making the choice.在您“管理”任何获准使用的浏览器的企业场景中,您还可以预先配置每家餐厅的浏览器以自动提供一些标识(自定义标题或 cookie),并且您的服务器可以使用该识别信息来确定哪家餐厅正在做出选择。 This would require accessing your site only through pre-configured and approved and properly maintained browsers (which may be more pain than it's worth).这将需要仅通过预先配置、批准和正确维护的浏览器访问您的站点(这可能比它的价值更痛苦)。

For example, here's how you would configure a custom header on all requests with Microsoft Edge .例如,以下是如何为 Microsoft Edge 的所有请求配置自定义标头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM