Skip to content

Commit

Permalink
fix: Bumping Serve Up to 9.2.0 Broke Calls to Serve's API (#6598)
Browse files Browse the repository at this point in the history
* fix: Bumping Serve Up to 9.2.0 Broke Calls to Serve's API

Follow Up on 69125cc

* fix: Linting Errors

* fix: Linting Errors

* feat: Add Back OpenURL for gatsby serve --open option
  • Loading branch information
trvsysadmin authored and KyleAMathews committed Jul 20, 2018
1 parent c5a74a8 commit ce9c3a8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/gatsby/src/commands/serve.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
/* @flow weak */
const serve = require(`serve`)
const handler = require(`serve-handler`)
const openurl = require(`opn`)
const http = require(`http`)
const signalExit = require(`signal-exit`)

module.exports = program => {
let { port, open, directory } = program
let { port, open } = program
port = typeof port === `string` ? parseInt(port, 10) : port

let server = serve(`${directory}/public`, { port, open })
let server = http.createServer((request, response) => handler(request, response, {
"public": `public`,
}),
)

server.listen(port, () => {
let openUrlString = `http://localhost:` + port
console.log(`gatsby serve running at:`, openUrlString)
if (open) {
let openUrlString = `http://localhost:` + port
console.log(`Opening browser...`)
openurl(openUrlString)
}
})

signalExit((code, signal) => {
server.stop()
server.close()
})
}

0 comments on commit ce9c3a8

Please sign in to comment.