How to use the CORS function from restify

Find comprehensive JavaScript restify.CORS code examples handpicked from public code repositorys.

21
22
23
24
25
26
27
28
29
30
  });
  next();
});
server.use(restify.authorizationParser());
server.use(restify.fullResponse());
restify.CORS.ALLOW_HEADERS.push('authorization'); //the restify CORS headers don't come with authorization
server.use(restify.CORS());
server.use(validate.validationPlugin({ errorsAsArray: false })); //inline route validation support

server.get('/', function(req, res) {
fork icon9
star icon12
watch icon22

+ 3 other calls in file

88
89
90
91
92
93
94
95
96
97
  origins: nconf.get('CORS:Origins'),
  credentials: nconf.get('CORS:Credentials'),
  headers: nconf.get('CORS:Headers'),
};

server.pre( restify.CORS(corsOptions) );

if ( corsOptions.headers.length ) {
  server.on('MethodNotAllowed', require( path.join(__dirname, 'helpers', 'corsHelper.js') )() );
}
fork icon5
star icon3
watch icon9

8
9
10
11
12
13
14
15
16
api.listen(restifyPort, function () {
    console.log('%s listening at %s', api.name, api.url)
});

api.pre(restify.CORS());
// restify.CORS.ALLOW_HEADERS.push('authorization');
api.pre(restify.fullResponse());
api.use(restify.bodyParser());
api.use(restify.queryParser());
fork icon0
star icon2
watch icon2

+ 9 other calls in file

151
152
153
154
155
156
157
158
159
160

restify.CORS.ALLOW_HEADERS.push('auth-token');
restify.CORS.ALLOW_HEADERS.push('user-name');
restify.CORS.ALLOW_HEADERS.push('user-type');
restify.CORS.ALLOW_HEADERS.push('user-id');
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Origin");
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Credentials");
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Methods","GET");
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Methods","POST");
restify.CORS.ALLOW_HEADERS.push("Access-Control-Allow-Methods","PUT");
fork icon0
star icon0
watch icon0

+ 10 other calls in file

49
50
51
52
53
54
55
56
57
58

if (request.method.toUpperCase() === "OPTIONS") {

    // Send the CORS headers
    response.header("Access-Control-Allow-Credentials", true);
    response.header("Access-Control-Allow-Headers", restify.CORS.ALLOW_HEADERS.join(", "));
    response.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    response.header("Access-Control-Allow-Origin", request.headers.origin);
    response.header("Access-Control-Max-Age", 0);
    response.header("Content-type", "text/plain charset=UTF-8");
fork icon0
star icon0
watch icon2

37
38
39
40
41
42
43
44
45
46

// setup CORS to allow versioning
restify.CORS.ALLOW_HEADERS.push('accept-version');
restify.CORS.ALLOW_HEADERS.push('authorization');
restify.CORS.ALLOW_HEADERS.push('x-requested-with');
restify.CORS.ALLOW_HEADERS.push('accept');
this.server
    .use(requestLogger)
    .use(restify.CORS())
    .use(restify.fullResponse())
fork icon0
star icon0
watch icon1

+ 7 other calls in file