简体   繁体   English

服务器中间件允许的主机

[英]Allowed hosts for serverMiddleware

I have built a NUXT app, and I've added to it a serverMiddleware for handling some REST endpoints and connecting to my database.我构建了一个 NUXT 应用程序,并向其中添加了一个 serverMiddleware,用于处理一些 REST 端点并连接到我的数据库。

serverMiddleware: [
  { path: "/api", handler: "~/api/index.js" },
],

So my question is: How to restrict accessing to /api endpoints from only few hosts?所以我的问题是:如何限制仅从少数主机访问 /api 端点? (like having a list of ALLOWED_ORIGINS) (比如有一个 ALLOWED_ORIGINS 列表)

Setting Access-Control-Allow-Origin in the header solved the issue as explained more in-depth on this answer: https://stackoverflow.com/a/32481816/8816585在 header 中设置Access-Control-Allow-Origin解决了这个问题,因为这个答案有更深入的解释: https://stackoverflow.com/a/32481816/8816585

Since at the end, this part of Nuxt is a regular Express app.因为最后,这部分 Nuxt 是一个普通的 Express 应用程序。

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

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