-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
45 lines (38 loc) · 1.46 KB
/
app.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
var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path')
, config = require('./config')
, cluster = require('cluster');
cluster.on('exit', function(worker){
console.log('Worker ' + worker.id + ' died');
cluster.fork();
});
if (cluster.isMaster){
var count = require('os').cpus().length;
for (var i = 0; i < count; i++){
cluster.fork();
}
} else {
var app = express();
app.set('port', process.env.PORT || config.port || 3000);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.methodOverride());
app.use(app.router);
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.put('/-/user/org.couchdb.user:*', routes.user.add);
app.get('/-/user/org.couchdb.user:*', routes.user.get);
app.post('/_session', routes.user.login);
app.get('/:packagename', routes.get.meta);
app.get('/:packagename/:version', routes.get.version);
app.get('/:packagename/-/:filename', routes.get.artifact);
app.put('/:packagename', [express.bodyParser()], routes.publish.meta);
app.put('/:packagename/-/:filename/-rev/:revision', routes.publish.artifact);
app.put('/:packagename/:version/-tag/latest', [express.bodyParser()], routes.publish.tag);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
}