-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #237 from alehlopeh/master
Add serve command in cli
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Hapi from 'hapi' | ||
|
||
const debug = require('debug')('gatsby:application') | ||
|
||
module.exports = (program) => { | ||
const directory = program.directory | ||
|
||
debug('Serving /public') | ||
|
||
// Setup and start Hapi to static files. | ||
|
||
const server = new Hapi.Server() | ||
|
||
server.connection({ | ||
host: program.host, | ||
port: program.port, | ||
}) | ||
|
||
server.route({ | ||
method: 'GET', | ||
path: '/{path*}', | ||
handler: { | ||
directory: { | ||
path: `${directory}/public`, | ||
listing: false, | ||
index: true, | ||
}, | ||
}, | ||
}) | ||
|
||
|
||
server.start((e) => { | ||
if (e) { | ||
console.log(e) | ||
} | ||
return console.log('Listening at:', server.info.uri) | ||
}) | ||
} |