Commit dbf91fcb6b08833648216861b54b1bfea551ee35
Find css dep even if it is not in ./node_modules/
Charles Lehner committed on 4/2/2016, 3:33:24 AMParent: 4cd0e7ebc99a154fda9b7d201aaf74a5dd9ba62f
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -21,8 +21,10 @@ | ||
21 | 21 | var Mentions = require('ssb-mentions') |
22 | 22 | var Highlight = require('highlight.js') |
23 | 23 | var JsDiff = require('diff') |
24 | 24 | |
25 | +var hlCssPath = path.resolve(require.resolve('highlight.js'), '../../styles') | |
26 | + | |
25 | 27 | // render links to git objects and ssb objects |
26 | 28 | var blockRenderer = new marked.Renderer() |
27 | 29 | blockRenderer.urltransform = function (url) { |
28 | 30 | if (ref.isLink(url)) |
@@ -599,16 +601,20 @@ | ||
599 | 601 | else if (ref.isMsgId(dir)) |
600 | 602 | return serveMessage(req, dir, dirs.slice(1)) |
601 | 603 | else if (ref.isFeedId(dir)) |
602 | 604 | return serveUserPage(req, dir, dirs.slice(1)) |
605 | + else if (dir == 'static') | |
606 | + return serveFile(req, dirs) | |
607 | + else if (dir == 'highlight') | |
608 | + return serveFile(req, [hlCssPath].concat(dirs.slice(1)), true) | |
603 | 609 | else |
604 | - return serveFile(req, dirs) | |
610 | + return serve404(req) | |
605 | 611 | } |
606 | 612 | |
607 | - function serveFile(req, dirs) { | |
608 | - var filename = path.join.apply(path, [__dirname].concat(dirs)) | |
613 | + function serveFile(req, dirs, outside) { | |
614 | + var filename = path.resolve.apply(path, [__dirname].concat(dirs)) | |
609 | 615 | // prevent escaping base dir |
610 | - if (filename.indexOf('../') === 0) | |
616 | + if (!outside && filename.indexOf('../') === 0) | |
611 | 617 | return servePlainError(403, '403 Forbidden') |
612 | 618 | |
613 | 619 | return readNext(function (cb) { |
614 | 620 | fs.stat(filename, function (err, stats) { |
@@ -698,9 +704,9 @@ | ||
698 | 704 | }], |
699 | 705 | '<!doctype html><html><head><meta charset=utf-8>', |
700 | 706 | '<title>' + escapeHTML(title || 'git ssb') + '</title>', |
701 | 707 | '<link rel=stylesheet href="/static/styles.css"/>', |
702 | - '<link rel=stylesheet href="/node_modules/highlight.js/styles/github.css"/>', | |
708 | + '<link rel=stylesheet href="/highlight/github.css"/>', | |
703 | 709 | '</head>\n', |
704 | 710 | '<body>', |
705 | 711 | '<header>', |
706 | 712 | '<h1><a href="/">git ssb' + |
Built with git-ssb-web