Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ There is an online preview version of the API Designer, check it out a [differen
```
npm install -g api-designer

api-designer
api-designer --port=3000 --open-browser=true
```

This will start a local designer instance using the in-browser filesystem.
This example shows the default values for `--port` and `--open-browser`

## Embedding

Expand All @@ -42,7 +43,7 @@ The following example details how to embed the API Designer:
<script src="scripts/api-designer-parser.js"></script>
<script>
if (window.Worker) {
// enable optional web worker for raml parsing
// enable optional web worker for raml parsing
window.RAML.worker = new Worker('scripts/api-designer-worker.js#parser=./api-designer-parser.js&proxy=/proxy/');
}
</script>
Expand Down
14 changes: 11 additions & 3 deletions bin/api-designer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ var argv = require('yargs')
describe: 'Port number to run the API designer',
type: 'number'
})
.option('o', {
alias: 'open-browser',
default: true,
describe: 'Automatically open the browser when server starts',
type: 'boolean'
})
.argv

var app = express()
Expand All @@ -21,7 +27,7 @@ app.use(express.static(join(__dirname, '../dist')))

app.use('/proxy', function (req, res, next) {
if (req.method.toUpperCase() === 'OPTIONS') {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With')
return next()
}
Expand All @@ -40,7 +46,7 @@ app.use('/proxy', function (req, res, next) {
// Workaround for some remote services that do not handle
// multi-valued Accept header properly by omitting precedence
if (req.headers.accept) {
req.headers.accept = req.headers.accept.split(',')[0].trim()
req.headers.accept = req.headers.accept.split(',')[ 0 ].trim()
}

// Pipe the request data directly into the proxy request and back to the
Expand All @@ -52,5 +58,7 @@ app.use('/proxy', function (req, res, next) {
app.listen(argv.p, function () {
console.log('API designer running on port ' + argv.p + '...')

open('http://localhost:' + argv.p + '/')
if (argv.o) {
open('http://localhost:' + argv.p + '/')
}
})