Skip to content

Commit

Permalink
Serve the badge as svg type.
Browse files Browse the repository at this point in the history
- Hack the React view engine to support SVG, see
  reactjs/express-react-views#53
  • Loading branch information
lijunle committed Oct 21, 2015
1 parent 9a12865 commit 7dd0294
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ router.route('/token/:provider/:user/:repo')
// must place the svg router before the next one.
router.get('/:provider/:user/:repo/:branch/:report?.svg', (req, res) =>
reportModel.get(req.params)
.then(result => res.render('badge', result)));
.then(result => res.type('svg').render('badge', result)));

router.route('/:provider/:user/:repo/:report?')
.get(loginModel.validate, (req, res) =>
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ app.set('view engine', 'js');

app.engine('js', (filePath, options, callback) => {
logger.debug(`[app] render view file [${filePath}].`);
return viewEngine(filePath, options, callback);
return viewEngine(filePath, options, (error, html) => {
// HACK to support serve SVG, see reactjs/express-react-views#53
const raw = html.substring('<!DOCTYPE html>'.length);
const hack = raw.indexOf('<svg') === 0
? raw.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"')
: html;

callback(error, hack);
});
});

app.use((req, res, next) => {
Expand Down

0 comments on commit 7dd0294

Please sign in to comment.