Commit 36c63bc1828456bf3417ff9eb5187cfcb776b3b2
Consolidate serve functions
cel committed on 8/22/2018, 7:58:51 PMParent: c8c744f585c7b47c5bc661ec8df7d5caf8d21ed8
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -80,8 +80,11 @@ | ||
80 | 80 | } |
81 | 81 | |
82 | 82 | var m = urlIdRegex.exec(req.url) |
83 | 83 | |
84 | + if (m[4] === '/robots.txt') return serveRobots(req, res, conf) | |
85 | + if (req.url.startsWith('/static/')) return serveStatic(req, res, m[4]) | |
86 | + if (req.url.startsWith('/emoji/')) return serveEmoji(req, res, m[4]) | |
84 | 87 | if (req.url.startsWith('/user-feed/')) return serveUserFeed(req, res, m[4]) |
85 | 88 | else if (req.url.startsWith('/channel/')) return serveChannel(req, res, m[4]) |
86 | 89 | else if (req.url.startsWith('/.well-known/acme-challenge')) return serveAcmeChallenge(req, res) |
87 | 90 | else if (req.url.startsWith('/web/')) return serveWeb(req, res, m[4]) |
@@ -93,10 +96,10 @@ | ||
93 | 96 | switch (m[2]) { |
94 | 97 | case '%': return serveId(req, res, m[1], m[3], m[5]) |
95 | 98 | case '@': return serveFeed(req, res, m[1], m[3], m[5]) |
96 | 99 | case '&': return serveBlob(req, res, sbot, m[1]) |
97 | - default: return servePath(req, res, m[4], conf) | |
98 | 100 | } |
101 | + return respond(res, 404, 'Not found') | |
99 | 102 | } |
100 | 103 | |
101 | 104 | function serveFeed(req, res, feedId, ext) { |
102 | 105 | console.log("serving feed: " + feedId) |
@@ -495,20 +498,8 @@ | ||
495 | 498 | case 'rss': return 'text/xml' |
496 | 499 | } |
497 | 500 | } |
498 | 501 | |
499 | -function servePath(req, res, url, conf) { | |
500 | - switch (url) { | |
501 | - case '/robots.txt': return serveRobots(req, res, conf) | |
502 | - } | |
503 | - var m = /^(\/?[^\/]*)(\/.*)?$/.exec(url) | |
504 | - switch (m[1]) { | |
505 | - case '/static': return serveStatic(req, res, m[2]) | |
506 | - case '/emoji': return serveEmoji(req, res, m[2]) | |
507 | - } | |
508 | - return respond(res, 404, 'Not found') | |
509 | -} | |
510 | - | |
511 | 502 | function ifModified(req, lastMod) { |
512 | 503 | var ifModSince = req.headers['if-modified-since'] |
513 | 504 | if (!ifModSince) return false |
514 | 505 | var d = new Date(ifModSince) |
Built with git-ssb-web