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

Commit

Permalink
fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
hiendv committed Aug 19, 2016
1 parent 761dd6a commit 9926d7d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
APP_PORT=1406
APP_URL=
APP_CACHE=1000
APP_CACHE=
GITHUB_TOKEN=PersonalAccessToken
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ Configurations are defined in `.env` file.
# Application port
APP_PORT=1406
# Where static files are hosted
APP_URL=
# Cache. Leave it null or 0 to disable (null: APP_CACHE=)
APP_CACHE=1000
# Cache expiration in ms. Leave it null to disable
APP_CACHE=
# GitHub personal access token. See https://github.com/settings/tokens
GITHUB_TOKEN=PersonalAccessToken
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dotenv": "^2.0.0",
"koa": "^1.2.1",
"koa-route": "^2.4.2",
"koa-static": "^2.0.0",
"koa-send": "^3.2.0",
"memoizee": "^0.4.1",
"octokat": "^0.4.18"
},
Expand Down
3 changes: 0 additions & 3 deletions src/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ let Badge = function (app, env) {
}

Badge.prototype.draw = function (src) {
if (this.$env.APP_URL) {
return this.$env.APP_URL + '/' + src
}
return '/' + src
}

Expand Down
18 changes: 6 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
require('dotenv').config()

import {version} from '../package.json'
import path from 'path'
import crypto from 'crypto'

import Koa from 'koa'
import Route from 'koa-route'
import Serve from 'koa-static'
import Send from 'koa-send'

import Octokat from 'octokat'
import Badge from './Badge'
Expand All @@ -19,11 +18,6 @@ app.context.github = new Octokat({

const badge = new Badge(app.context, process.env)

app.use(Serve(path.join(__dirname, '../public'), {
gzip: true,
maxage: 0
}))

app.use(Route.get('/', function * () {
this.body = 'Hireable v' + version
}))
Expand All @@ -33,13 +27,13 @@ app.use(Route.get('/p/:user', function * (user) {
}))

app.use(Route.get('/:user/:repo?', function * show (id, repo) {
let source
yield badge.show(id, repo).then(src => {
this.body = null
this.response.etag = crypto.createHash('md5').update(src).digest('hex')
this.set('Cache-Control', 'no-cache, no-store, must-revalidate')
this.redirect(src)
this.status = 301
this.set('etag', crypto.createHash('md5').update(src).digest('hex'))
this.set('Cache-Control', 'private')
source = src
})
yield Send(this, './public/' + source)
}))

app.listen(process.env.APP_PORT)
Expand Down

0 comments on commit 9926d7d

Please sign in to comment.