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

Commit

Permalink
Resolve #9
Browse files Browse the repository at this point in the history
  • Loading branch information
hiendv committed Sep 11, 2016
1 parent 23e3142 commit 4e5560a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ import Badge from './Badge'
const _ROUTES = {
user () {
return {
pattern: new Pattern('(/*):user(/)'),
pattern: new Pattern('(/*):user(/:style)(/)'),
then (request, response, params) {
(new User(new Badge())).show(params.user).then(user => {
response.setHeader('Cache-Control', 'private')
response.setHeader('Hireable', ~~user.hireable) // Double bitwise NOT
Send(request, user.badge).pipe(response)
})
try {
(new User(new Badge(params.style))).show(params.user).then(user => {
response.setHeader('Cache-Control', 'private')
response.setHeader('Hireable', ~~user.hireable) // Double bitwise NOT
Send(request, user.badge).pipe(response)
})
} catch (error) {
if (error.code === 'ENOENT') {
this.abort(403, 'Style Not Supported')
return
}

throw error
}
}
}
},
Expand All @@ -44,9 +53,10 @@ let _dispatch = function (request, response) {
response.writeHead(code)
response.end(msg)
}
this.abort = abort

if (request.method !== 'GET') {
return abort(403, 'Supported methods: GET')
return abort(405, 'Method Not Allowed')
}

let parts = url.parse(request.url)
Expand All @@ -56,7 +66,7 @@ let _dispatch = function (request, response) {
}

for (let key in _ROUTES) {
let route = _ROUTES[key]()
let route = _ROUTES[key].call(this)
let params = route.pattern.match(parts.pathname)
if (!params) {
continue
Expand Down
7 changes: 5 additions & 2 deletions src/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ let _loadDirectory = function (directory) {
}

let Badge = function (style, directory) {
_loadStyle.call(this, style)
_loadDirectory.call(this, directory)
_loadSources.call(this)
this.setStyle(style)
}

Badge.prototype = {
Expand All @@ -70,6 +69,10 @@ Badge.prototype = {
style () {
return _style
},
setStyle (style) {
_loadStyle.call(this, style)
_loadSources.call(this)
},
images () {
return _IMAGES
},
Expand Down

0 comments on commit 4e5560a

Please # to comment.