Skip to content

Commit

Permalink
Merge e596168 into 3637b31
Browse files Browse the repository at this point in the history
  • Loading branch information
strugee committed Apr 10, 2018
2 parents 3637b31 + e596168 commit 771b4d1
Show file tree
Hide file tree
Showing 27 changed files with 2,326 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -15,7 +15,7 @@ addons:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
script: "(npm test || npm test) && sudo sh -c 'export PATH=\"'\"$(dirname $(which node)):$PATH\"'\" && npm run test:root && npm run test:install'"
script: "(npm test || npm test) && npm run test:install && sudo sh -c 'export PATH=\"'\"$(dirname $(which node)):$PATH\"'\" && npm run test:root'"
before_script:
- "./test/hosts.sh"
before_install:
Expand Down
71 changes: 46 additions & 25 deletions lib/app.js
Expand Up @@ -74,7 +74,9 @@ var urlparse = require("url").parse,
cluster = require("cluster"),
Client = require("./model/client").Client,
User = require("./model/user").User,
AccessToken = require("./model/accesstoken").AccessToken;
AccessToken = require("./model/accesstoken").AccessToken,
BearerToken = require("./model/bearertoken").BearerToken,
negotiate = require("./negotiate");

var makeApp = function(configBase, callback) {

Expand Down Expand Up @@ -268,21 +270,23 @@ var makeApp = function(configBase, callback) {
appServer = http.createServer(app);
}

cluster.worker.on("message", function(msg) {
if (msg.cmd === "gracefulShutdown") {
log.debug("Shutting down worker due to zero-downtime restart request.");
appServer.close(function() {
db.disconnect(function() {
cluster.worker.disconnect();
});
});

// This doesn't need to be in the above callback chain because it doesn't interact with anything
if (useBounce) {
bounce.close();
}
}
});
if (cluster.worker) {
cluster.worker.on("message", function(msg) {
if (msg.cmd === "gracefulShutdown") {
log.debug("Shutting down worker due to zero-downtime restart request.");
appServer.close(function() {
db.disconnect(function() {
cluster.worker.disconnect();
});
});

// This doesn't need to be in the above callback chain because it doesn't interact with anything
if (useBounce) {
bounce.close();
}
}
});
}

app.config = config;

Expand Down Expand Up @@ -513,7 +517,15 @@ var makeApp = function(configBase, callback) {

if (!config.noweb) {
web.addRoutes(app, session);
// We do context negotation for this unique route
app.get("/:nickname", session, negotiate({
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"": api.profileStack,
"application/activity+json": api.profileStack,
html: web.profileStack
}));
} else {
// No web, so this always does the API route
app.get("/:nickname", api.profileStack);
// A route to show the API doc at root
app.get("/", function(req, res, next) {

Expand Down Expand Up @@ -643,7 +655,9 @@ var makeApp = function(configBase, callback) {
bounce.on("listening", bounceSuccess);
bounce.listen(80, address);
} else {
cluster.worker.send({msg: "listening"});
if (cluster.worker) {
cluster.worker.send({msg: "listening"});
}
callback(null);
}
};
Expand Down Expand Up @@ -734,14 +748,21 @@ var makeApp = function(configBase, callback) {
group()(null);
} else {
_.each(props.tokens, function(tprops) {
var xprops = {
username: user.nickname,
access_token: tprops.token,
token_secret: tprops.token_secret,
consumer_key: tprops.client_id
};
var at = new AccessToken(xprops);
at.save(group());
// BearerToken or AccessToken?
if (tprops.scope || !tprops.token_secret) {
var bprops = _.extend(tprops, {
nickname: user.nickname
});
BearerToken.create(bprops, group());
} else {
var xprops = {
username: user.nickname,
access_token: tprops.token,
token_secret: tprops.token_secret,
consumer_key: tprops.client_id
};
AccessToken.create(xprops, group());
}
});
}
},
Expand Down

0 comments on commit 771b4d1

Please sign in to comment.