简体   繁体   English

使用Express在Node JS中路由问题

[英]Route issue in Node JS with express

I have a godaddy domain being redirected to an instance of EC2 with an elastic IP. 我有一个Godaddy域通过弹性IP重定向到EC2实例。 on instance there runs my NodeJS on port 5000. im redirecting 80 to 5000( till here everything works fine). 例如,在端口5000上运行我的NodeJS。将80重定向到5000(直到此处一切正常)。 In express i have a route say '/Calculate/:Type', which is visited when some caculate button is pressed. 在快递中,我有一条路线说“ / Calculate /:Type”,当按下某些计算按钮时会访问该路线。 ideally the when button is pressed a request to server should go like http://example.com/calculate/3 but here is goes http://example.com//calculate/3 an extra / before caculate ruins the entire route. 理想情况下,按下“何时”按钮时,对服务器的请求应该像http://example.com/calculate/3一样,但是这里是http://example.com//calculate/3一个额外的/,所以caculate会破坏整个路由。 can someone please tell me why is it happening? 有人可以告诉我为什么会这样吗?

Try adding a period in front of /Calculate/:Type so 尝试在/ Calculate /:Type前面添加句点,这样

'./Calculate/:Type' in your express route 快速路线中的'./Calculate/:Type'

Ahh so it seems like you may be hitting a CORS error. 嗯,看来您可能遇到了CORS错误。 Is your webserver and dataserver on the same url? 您的网络服务器和数据服务器是否在同一网址上?

  • Best option : Put the node instance serving your app on yourdomain.com, and make your api endpoint api.yourdomain.com/Calculate/:Type 最佳选择:将为您的应用提供服务的节点实例放在yourdomain.com上,并使您的api端点api.yourdomain.com/Calculate/:Type
  • Other Option: exposing yourself to security risks by adding a 'Access-Control-Allow-Origin = *' in the header of your response 其他选择:在响应的标题中添加“ Access-Control-Allow-Origin = *”,使自己面临安全风险
  • Other Option: expose yourself to security change your settings in htaccess to allow all, or the specific domain 其他选项:使自己处于安全状态更改htaccess中的设置以允许全部或特定域

修改定义findone查询的路由,并从中删除正斜杠。

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

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