gancio/server/routes.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-08-09 01:58:11 +02:00
const path = require('path')
const config = require('config')
const express = require('express')
2019-10-10 11:23:44 +02:00
const cors = require('cors')
2019-08-09 01:58:11 +02:00
const api = require('./api')
const oauth = require('./api/oauth')
2019-10-30 14:58:40 +01:00
const cookieParser = require('cookie-parser')
2019-08-09 01:58:11 +02:00
const federation = require('./federation')
const webfinger = require('./federation/webfinger')
const { spamFilter } = require('./federation/helpers')
2019-08-25 14:34:26 +02:00
const debug = require('debug')('routes')
2019-09-17 18:16:59 +02:00
const exportController = require('./api/controller/export')
2019-10-11 18:34:14 +02:00
const helpers = require('./helpers')
const app = express()
2019-10-11 18:34:14 +02:00
app.use((req, res, next) => {
2019-09-11 19:12:24 +02:00
debug(req.path)
next()
})
// ignore unimplemented ping url from fediverse
app.use(spamFilter)
2019-10-11 18:34:14 +02:00
// serve favicon and static content
app.use('/favicon.ico', express.static(path.resolve(config.favicon || './assets/favicon.ico')))
app.use('/logo.png', express.static('./static/gancio.png'))
app.use('/media/', express.static(config.upload_path))
2019-10-11 18:34:14 +02:00
2020-01-03 22:24:27 +01:00
// initialize instance settings / authentication / locale
app.use(cookieParser())
app.use(helpers.initMiddleware)
2019-10-28 17:33:20 +01:00
// rss/ics/atom feed
app.get('/feed/:type', cors(), exportController.export)
2019-10-11 18:34:14 +02:00
// api!
app.use('/api', api)
2020-01-03 22:24:27 +01:00
app.use('/oauth', oauth)
2019-08-09 01:58:11 +02:00
// federation api / activitypub / webfinger / nodeinfo
app.use('/.well-known', webfinger)
app.use('/federation', federation)
2019-08-09 01:58:11 +02:00
// // Handle 500
2020-01-03 22:24:27 +01:00
app.use((error, req, res, next) => {
debug('Error 500: %s', error)
res.status(500).send('500: Internal Server Error')
})
2019-08-25 14:34:26 +02:00
2019-10-11 18:34:14 +02:00
// remaining request goes to nuxt
2020-01-03 22:24:27 +01:00
// first nuxt component is ./pages/index.vue (with ./layouts/default.vue)
2019-09-17 18:16:59 +02:00
module.exports = app