Tag: 访问控制

快递ipfilter的具体路线?

是否有可能应用不同的IPfilter不同的路线? 例如,我想只有123.123.123.123的人可以访问我的服务器/test路由,只有来自124.124.124.124的人可以访问我的服务器/路由。 我知道express-ipfilter可以通过IP地址来限制站点访问。 但是它不能将filter应用到特定的路由。 我也知道添加app.use(ipfilter(ips, {})); 在路线的中间可以应用仅对以下路线进行过滤: var express = require('express'), ipfilter = require('express-ipfilter').IpFilter; var ips = ['::ffff:127.0.0.1']; var app = express(); app.get('/test', function(req, res) { res.send('test'); }); app.use(ipfilter(ips, {})); // the ipfilter only applies to the routes below app.get('/', function(req, res) { res.send('Hello World'); }); app.listen(3000); 但我想要不同的路线不同的filter。 是否有可能做到这一点?

如何在express js中添加'res.addHeader(“Access-Control-Allow-Origin”,“*”)?

在我的应用程序中,我使用angularjs和cordova作为前端,并使用expression式和节点js作为服务器的后端。 我的客户端在http:// localhost:9000上运行,但是,我的express js在http:// localhost:3000上运行 。 我需要从快递API获取数据。 访问时,它说' XMLHttpRequest cannot load http://localhost:3000/data. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access. 为此,我需要添加res.addHeader("Access-Control-Allow-Origin", "*") 。 它是从其他域访问一个域。 如何在express js中添加这个头文件? 请帮我解决

带有ssl和Access-Control-Header的socket.io / node.js

我设置了一个节点服务器,并在激活ssl(官方,非自行分配的证书)时收到错误消息。 错误消息: XMLHttpRequest cannot load https://servername:8081/socket.io/… No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://servername' is therefore not allowed access. results:1 但实际上,我在.htaccess文件中包含了以下代码: <IfModule mod_headers.c> Header set Access-Control-Allow-Origin * Header set Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT" </IfModule> apache标题模块被安装。 我的服务器: var fs = require('fs'); var https = require('https'); var express = require ('express'); var options = { key: […]

Access-Control-Allow-Origin使用Node.js,express和socket.io在OpenShift上

正如标题所示,我无法远程访问OpenShift上托pipe的node.js实例。 我在浏览器的控制台中收到的错误如下所示: XMLHttpRequest无法加载http://app-domain.rhcloud.com:8000/socket.io/?EIO=3&transport=polling&t=1430117973290-2 。 请求的资源上没有“Access-Control-Allow-Origin”标题。 Origin'http:// localhost:8383 '因此不被允许访问。 (08:59:33:579 | error,javascript)at public_html / index.html 我意识到,标题需要设置为允许跨域请求,我已经尝试了几种不同的做法,在我的服务器代码。 目前服务器和客户端代码如下所示: 服务器: #!/bin/env node var test = { init: function() { test.protocol = require('http'); test.express = require('express'); test.fs = require('fs'); test.socket = require('socket.io'); test.key(); test.setup(); test.cache(); test.handlers(); test.server(); test.start(); }, key: function() { test.cache_get = function(key) { return test.zcache[key]; }; […]

在Sails中从模型中获取当前用户

我在Sails中使用我的模型的toJSON()方法,以便在通过应用程序的API公开模型时控制其某些属性的可见性。 为了决定要显示哪些属性以及哪些要省略,我需要知道当前用户的权限。 那么,如何从模型中获取当前用户呢? 还是有更好的方法(模式)来解决这个问题? 这是我想要实现的一些示例代码: toJSON: function () { var result = {}; result.firstName = this.firstName; result.lastName = this.lastName; // Exposing emails only to admin users. if (currentUser.isAdmin()) { result.email = this.email; } return result; }

在GraphQL服务器中实现访问控制的好模式是什么?

背景: 我有一套模型,其中包括用户和其他各种模型,其中一些包含对用户的引用。 我通过Graffiti生成的GraphQL API公开了这些模型,Mongo数据库使用graffiti-mongoose适配器作为后台。 我当前的REST API(我正在迁移到GraphQL)使用JSON Web令牌来validation用户,并在服务器端有一些自定义权限逻辑来处理访问控制。 问题: 我想根据当前login的用户限制对GraphQL中的对象的访问。 有些模型应该可以通过未经authentication的调用进行读取。 大多数其他模型只能由创build它们的用户访问。 通过Graffiti生成的APIpipe理对象访问控制的最佳方式是什么? 一般来说,GraphQL的访问控制是否有良好的模式? 特别是,有没有什么好的例子或图书馆与涂鸦做呢? 笔记: 据我所知, 已经实施了涂鸦 – mongoose的前后钩子,并且可以用它们进行基本的二进制validation。 我想看看更详细的访问控制逻辑如何在GraphQL API中使用。 将来,我们需要支持像pipe理员那样可以访问由特定用户组创build的模型实例的东西(例如,其用户的机构包括pipe理员)。

Socket.io访问控制允许=来自远程站点的原始错误

我正尝试从另一个站点访问一个socket.io服务器。 它工作了几个星期,但现在我不断收到以下错误。 从heroku服务器访问节点上的服务器时会发生这种情况。 错误是: XMLHttpRequest cannot load http://site2.nodester.com/socket.io/xhr-polling//1311008802545. Origin http://site1.heroku.com is not allowed by Access-Control-Allow-Origin. Resource interpreted as Script but transferred with MIME type text/plain. Uncaught SyntaxError: Unexpected identifier 以下是我如何连接到套接字: socket = new io.Socket( 'site2.nodester.com', {port: 80, rememberTransport: false} ); 这里是服务器代码: // requires server = http.createServer(function(req, res){ // server stuffs }), server.listen(8362); var io = […]