forked from visnup/npm-www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
106 lines (83 loc) · 3.55 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// XXX Maybe split route handlers into separate modules?
// Could do some kind of fs.readdir and then require them all.
var routes = require('routes')
, Router = routes.Router
, Route = routes.Route
, router = new Router()
, config = require('./config.js')
module.exports = router
// static stuff serves out of the static folder.
var static = require('./routes/static.js')
router.addRoute('/static/*?', static)
router.addRoute('/favicon.ico', static)
router.addRoute('/install.sh', static)
router.addRoute('/robots.txt', static)
router.addRoute('/ca.crt', static)
router.addRoute('/api/*?', static)
router.addRoute('/api', static)
// st should really just let you do either index.html OR autoindex
router.addRoute('/doc/?', function (req, res) {
req.url = require('url').parse(req.url).pathname
if (!req.url.match(/\/$/)) return res.redirect(req.url+'/')
req.url += 'index.html'
static(req, res)
})
router.addRoute('/doc/*', static)
router.addRoute('/stylus/*?', require('./routes/stylus.js'))
// legacy
router.addRoute('/dist/*?', distRedirect)
router.addRoute('/dist', distRedirect)
function distRedirect (req, res) {
var s = req.splats && req.splats[0] || ''
return res.redirect('http://nodejs.org/dist/npm/' + s, 301)
}
router.addRoute('/search', require('./routes/search.js'))
router.addRoute('/login', require('./routes/login.js'))
router.addRoute('/profile-edit', require('./routes/profile-edit.js'))
router.addRoute('/star', require('./routes/star.js'))
router.addRoute('/email-edit', require('./routes/email-edit.js'))
router.addRoute('/email-edit/:action/:token', require('./routes/email-edit.js'))
router.addRoute('/profile/:name', profRedir)
router.addRoute('/profile', profRedir)
router.addRoute('/~/:name', profRedir)
function profRedir (req, res) {
var n = req.params && req.params.name || ''
res.redirect('/~' + n, 301)
}
router.addRoute('/~:name', require('./routes/profile.js'))
router.addRoute('/~', require('./routes/profile.js'))
router.addRoute('/session', require('./routes/session-dump.js'))
var logout = require('./routes/logout.js')
router.addRoute('/logout', logout)
router.addRoute('/logout/*?', logout)
router.addRoute('/password', require('./routes/password.js'))
router.addRoute('/signup', require('./routes/signup.js'))
var forgot = require('./routes/forgot-password.js')
router.addRoute('/forgot', forgot)
router.addRoute('/forgot/:token', forgot)
router.addRoute('/about', require('./routes/about.js'))
router.addRoute('/whoshiring', require('./routes/whoshiring.js'))
router.addRoute('/joinwhoshiring', require('./routes/payments.js'))
router.addRoute('/', function (req, res) {
var search = req.url && req.url.split('?')[1]
if (search) return res.redirect('/search?' + search, 301)
return require('./routes/index.js')(req, res)
})
// The package details page
var packagePage = require('./routes/package-page.js')
router.addRoute('/package/:name/:version', packagePage)
router.addRoute('/package/:name', packagePage)
router.addRoute('/keyword/:kw', function (q, s) {
return s.redirect('/browse/keyword/' + q.params.kw, 301)
})
router.addRoute('/browse/*?', require('./routes/browse.js'))
var ra = require('./routes/recentauthors.js')
router.addRoute('/recent-authors', ra)
router.addRoute('/recent-authors/*?', ra)
var healthchecks = require('./routes/healthchecks.js')
router.addRoute('/ping', healthchecks.ping)
router.addRoute('/status', healthchecks.status)
// npmjs.org/npm -> npmjs.org/package/npm
// if nothing else matches.
router.addRoute('/:name', require('./routes/maybe-package.js'))
router.addRoute('/-/csplog', require('./routes/csplog.js'))