Hapi = require('hapi')
|
|
|
|
exports.startServer = (port, publicPath, callback) ->
|
|
|
|
# Start server on port specified in brunch-config
|
|
server = new Hapi.Server port
|
|
|
|
# Reverse proxy to Untappd API
|
|
server.route
|
|
method: 'GET'
|
|
path: '/api/untappd/search/{path*}'
|
|
handler:
|
|
proxy:
|
|
mapUri: (request, callback) ->
|
|
url = "http://api.untappd.com/v4/search/#{request.params.path}?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&q=#{request.query.q}"
|
|
callback null, url
|
|
redirects: 5
|
|
timeout: 5000
|
|
|
|
# Serve scripts
|
|
server.route
|
|
method: 'GET'
|
|
path: '/scripts/{file*1}'
|
|
handler:
|
|
directory: {path: "#{publicPath}/scripts"}
|
|
|
|
# Serve styles
|
|
server.route
|
|
method: 'GET'
|
|
path: '/styles/{file*1}'
|
|
handler:
|
|
directory: {path: "#{publicPath}/styles"}
|
|
|
|
# Serve images
|
|
server.route
|
|
method: 'GET'
|
|
path: '/images/{file*1}'
|
|
handler:
|
|
directory: {path: "#{publicPath}/images"}
|
|
|
|
# Serve fonts
|
|
server.route
|
|
method: 'GET'
|
|
path: '/fonts/{file*1}'
|
|
handler:
|
|
directory: {path: "#{publicPath}/fonts"}
|
|
|
|
# Serve robots.txt
|
|
server.route
|
|
method: 'GET'
|
|
path: '/robots.txt'
|
|
handler:
|
|
file: "#{publicPath}/robots.txt"
|
|
|
|
# Catch-all route
|
|
server.route
|
|
method: 'GET'
|
|
path: '/{path*}'
|
|
handler:
|
|
file: "#{publicPath}/index.html"
|
|
|
|
# Start up server
|
|
server.start ->
|
|
console.log "Server running at #{server.info.uri}"
|