Skip to content
This repository has been archived by the owner on Feb 4, 2018. It is now read-only.

Commit

Permalink
Enable cors on deploy and apps
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Dec 29, 2016
1 parent 735f783 commit 2c8a54e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"brfs": "^1.4.3",
"browser-request": "^0.3.3",
"browserify": "^13.0.0",
"cors": "^2.8.1",
"date-and-time": "^0.3.0",
"dom-css": "^2.0.0",
"envify": "^3.4.1",
Expand Down
5 changes: 5 additions & 0 deletions server/cors-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var path = require('path')
var fs = require('fs')

var contents = fs.readFileSync(path.join(process.env['HOME'], '.binder/cors.conf'), 'utf8')
module.exports = JSON.parse(contents)
9 changes: 7 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var expressWs = require('express-ws')
var bodyParser = require('body-parser')
var app = express()
var http = require('http').Server(app)
var cors = require('cors');
var io = require('socket.io')(http)
var assign = require('object-assign')
var merge = require('lodash.merge')
Expand All @@ -20,6 +21,10 @@ app.use('/js', express.static(path.join(__dirname, '../public/js')))
app.use('/css', express.static(path.join(__dirname, '../public/css')))
app.use('/assets', express.static(path.join(__dirname, '../public/assets')))

// Cors options

var launchCorsOptions = require('./cors-settings')

// set once the server is started
var binder = null

Expand Down Expand Up @@ -63,15 +68,15 @@ app.get('/validate/:name', function (req, res) {

// API endpoints

app.get('/api/deploy/:templateName', function (req, res) {
app.get('/api/deploy/:templateName', cors(launchCorsOptions), function (req, res) {
var name = req.params.templateName
binder.deployBinder(name, function (err, status) {
if (err) return res.status(500).end()
return res.json(status)
})
})

app.get('/api/apps/:templateName/:id', function (req, res) {
app.get('/api/apps/:templateName/:id', cors(launchCorsOptions), function (req, res) {
var name = req.params.templateName
var id = req.params.id
binder.getDeployStatus(name, id, function (err, status) {
Expand Down

0 comments on commit 2c8a54e

Please sign in to comment.