Skip to content

Commit

Permalink
add CORS to restify
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbradley committed Feb 10, 2017
1 parent 93109fe commit 352ac23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/rest/RouteHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export default class RouteHandler {
try {
let controller: TestJobController = TestJobController.getInstance();
controller.count().then((length:number) => {
console.log('count is ' + length);
Log.info('RouteHandler::queueLength() - Number of waiting or paused jobs: ' + length + '.');
res.json(200, {length:length});
}).catch((err) => {
Log.error('RouteHandler::queueLength() - ERROR getting length: ' + err);
res.json(400, {error:err});
})
} catch(err) {
Log.error('RouteHandler::queueLength() - ERROR getting length: ' + err);
res.json(400, {error:err});
}
return next();
Expand Down
8 changes: 8 additions & 0 deletions src/rest/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export default class Server {
name: 'AutoTest'
});

// support CORS
that.rest.use(
function crossOrigin(req,res,next){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
return next();
});

// REST hooks
// https://zapier.com/developer/documentation/v2/rest-hooks/
// that.rest.get('/api/hooks/:id', RouteHandler.getHook);
Expand Down

0 comments on commit 352ac23

Please sign in to comment.