Clean up the console logs

To make it easier to follow the flow.
parent a05b91f3
......@@ -18,7 +18,7 @@ const channels = require('./channels')
const app = express(feathers())
// Hardcoded LocalTunnel URL for testing federation.
const localDomain = 'avgrtijmup.localtunnel.me'
const localDomain = 'iymtkfkwhc.localtunnel.me'
// Load app configuration
app.configure(configuration())
......@@ -31,9 +31,15 @@ app.use(express.urlencoded({ extended: true }))
app.use(favicon(path.join(app.get('public'), 'favicon.ico')))
app.use('/.well-known/webfinger', function (req, res, next) {
console.log(`WebFinger request received for resource: ${req.query.resource}`)
console.log('🤞 WebFinger request')
console.log(` ↳ Resource: ${req.query.resource}`)
// Set correct content type.
const contentType = 'application/jrd+json; charset=utf-8'
res.set('Content-Type', contentType)
console.log(' ↳ Content-Type: application/jrd+json')
res.set('Content-Type', 'application/jrd+json; charset=utf-8')
const response = JSON.parse(`{
"subject": "acct:person@${localDomain}",
"links": [{
......@@ -42,16 +48,44 @@ app.use('/.well-known/webfinger', function (req, res, next) {
"href": "https://${localDomain}/"
}]
}`)
console.log(response)
console.log(' ↳ Sending WebFinger response.\n')
res.send(response)
})
app.use('/inbox', function (req, res, next) {
console.log('Inbox hit')
console.log('📥 Inbox')
console.log(` ↳ Returning empty response.\n`)
res.send({})
})
app.use('/outbox', function (req, res, next) {
console.log('📤 Outbox')
console.log(` ↳ Returning empty response.\n`)
res.send({})
})
app.use('/following', function (req, res, next) {
console.log('👀 Following')
console.log(` ↳ Returning empty response.\n`)
res.send({})
})
app.use('/followers', function (req, res, next) {
console.log('👀 Followers')
console.log(` ↳ Returning empty response.\n`)
res.send({})
})
app.use('/', function (req, res, next) {
// Only capture the root URL, do not act
// as a catch-all.
if (req.originalUrl !== '/') {
return next()
}
res.format({
'text/html': function () {
......@@ -59,12 +93,20 @@ app.use('/', function (req, res, next) {
},
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"': function () {
res.set('Content-Type', 'application/activity+json; charset=utf-8')
console.log('🎭 Actor request')
// Set correct content type.
const contentType = 'application/activity+json; charset=utf-8'
res.set('Content-Type', contentType)
console.log(` ↳ Content-Type: application/activity+json`)
// WebFinger support is not a requirement in the ActivityPub spec
// but it is required for federation with Mastodon.
// https://github.com/tootsuite/mastodon/issues/4906#issuecomment-328844846
console.log(` ↳ Link: acct:person@${localDomain} → https://${localDomain}/ (for application/activity+json)'`)
res.set('Link', `<https://${localDomain}/.well-known/webfinger?resource=acct%3Aperson%40${localDomain}>; rel="lrdd"; type="application/xrd+xml", <https://${localDomain}/>; rel="alternate"; type="application/activity+json"`)
// The structure of this reponse is modelled on the Mastodon response
......@@ -74,6 +116,9 @@ app.use('/', function (req, res, next) {
// the presence of an inbox endpoint and a link header pointing to
// the WebFinger endpoint (and the implementation of the webfinger
// endpoint itself.)
console.log(' ↳ Returning ActivityStream object.\n')
const sampleActorActivityStreamObject = JSON.parse(`{
"@context": [
"https://www.w3.org/ns/activitystreams",
......@@ -123,7 +168,6 @@ app.use('/', function (req, res, next) {
res.send(sampleActorActivityStreamObject)
}
})
next()
})
// Set up Plugins and providers
......@@ -139,8 +183,10 @@ app.configure(channels)
// Configure a middleware for 404s and the error handler
app.use(function (req, res) {
console.log(req.url)
console.log(`\n⚠️ Unhandled route`)
console.log(` ↳ ${req.url}\n`)
})
app.use(express.notFound())
app.use(express.errorHandler({ logger }))
......
......@@ -9,5 +9,5 @@ process.on('unhandledRejection', (reason, p) =>
)
server.on('listening', () =>
logger.info('Feathers application started on http://%s:%d', app.get('host'), port)
logger.info('ActivityPub Spike running on http://%s:%d\n', app.get('host'), port)
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment