Verified Commit b8931ee8 authored by les's avatar les
Browse files

refactoring routes

parent 15cdba96
......@@ -32,6 +32,9 @@ export default {
components: { DbStep, Settings, Completed },
middleware: 'setup',
layout: 'iframe',
head: {
title: 'Setup',
},
auth: false,
data () {
return {
......
......@@ -4,7 +4,7 @@ const config = require('../../config')
const fs = require('fs')
const { Op } = require('sequelize')
const intersection = require('lodash/intersection')
const linkifyHtml = require('linkifyjs/html')
const linkifyHtml = require('linkify-html')
const Sequelize = require('sequelize')
const dayjs = require('dayjs')
const helpers = require('../../helpers')
......
......@@ -4,7 +4,7 @@ const APUser = require('../api/models/ap_user')
const log = require('../log')
const helpers = require('../helpers')
const linkifyHtml = require('linkifyjs/html')
const linkifyHtml = require('linkify-html')
module.exports = {
......
const ical = require('ical.js')
const settingsController = require('./api/controller/settings')
const acceptLanguage = require('accept-language')
const express = require('express')
const dayjs = require('dayjs')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(timezone)
......@@ -78,6 +78,30 @@ module.exports = {
next()
},
serveStatic () {
const router = express.Router()
// serve logo, favicon, event's images/thumb
router.use('/media/', express.static(config.upload_path))
router.use('/noimg.svg', express.static('./static/noimg.svg'))
router.use('/logo.png', (req, res, next) => {
const logoPath = req.settings.logo || './static/gancio'
return express.static(logoPath + '.png')(req, res, next)
})
router.use('/favicon.ico', (req, res, next) => {
const faviconPath = req.settings.logo || './assets/favicon'
return express.static(faviconPath + '.ico')(req, res, next)
})
return router
},
logRequest (req, res, next) {
log.debug(`${req.method} ${req.path}`)
next()
},
async getImageFromURL (url) {
log.debug(`getImageFromURL ${url}`)
const filename = crypto.randomBytes(16).toString('hex') + '.jpg'
......
const config = require('config')
const express = require('express')
const cors = require('cors')
const api = require('./api')
const oauth = require('./api/oauth')
const auth = require('./api/auth')
const cookieParser = require('cookie-parser')
const federation = require('./federation')
const webfinger = require('./federation/webfinger')
const { spamFilter } = require('./federation/helpers')
const log = require('./log')
const exportController = require('./api/controller/export')
const eventController = require('./api/controller/event')
const announceController = require('./api/controller/announce')
// const metricsController = require('./metrics')
// const promBundle = require('express-prom-bundle')
// const metricsMiddleware = promBundle({ includeMethod: true })
const config = require('./config')
const helpers = require('./helpers')
const app = express()
const log = require('./log')
const api = require('./api')
// ignore unimplemented ping url from fediverse
app.use(spamFilter)
// app.use(metricsMiddleware)
const app = express()
app.use((req, res, next) => {
log.debug(`${req.method} ${req.path}`)
next()
})
app.use(helpers.logRequest)
app.use('/media/', express.static(config.upload_path))
// initialize instance settings / authentication / locale
app.use(helpers.initSettings)
app.use(helpers.serveStatic())
app.use('/noimg.svg', (req, res, next) => {
return express.static('./static/noimg.svg')
})
// ignore unimplemented ping url from fediverse
app.use(cookieParser())
// serve favicon and static content
app.use('/logo.png', (req, res, next) => {
const logoPath = req.settings.logo || './static/gancio'
return express.static(logoPath + '.png')(req, res, next)
})
app.use('/favicon.ico', (req, res, next) => {
const faviconPath = req.settings.logo || './assets/favicon'
return express.static(faviconPath + '.ico')(req, res, next)
})
// do not handle all routes on setup
if (!config.firstrun) {
const cors = require('cors')
const { spamFilter } = require('./federation/helpers')
const oauth = require('./api/oauth')
const auth = require('./api/auth')
const federation = require('./federation')
const webfinger = require('./federation/webfinger')
const exportController = require('./api/controller/export')
// rss/ics/atom feed
app.get('/feed/:type', cors(), exportController.export)
// rss/ics/atom feed
app.get('/feed/:type', cors(), exportController.export)
// federation api / activitypub / webfinger / nodeinfo
app.use('/.well-known', webfinger)
app.use('/federation', federation)
app.use(spamFilter)
// federation api / activitypub / webfinger / nodeinfo
app.use('/.well-known', webfinger)
app.use('/federation', federation)
// fill req.user if request is authenticated
app.use(auth.fillUser)
app.use(cookieParser())
app.use('/oauth', oauth)
// app.use(metricsMiddleware)
}
// fill req.user if request is authenticated
app.use(auth.fillUser)
// api!
app.use('/api', api)
app.use('/oauth', oauth)
// // Handle 500
app.use((error, req, res, next) => {
......@@ -75,8 +63,13 @@ app.use((error, req, res, next) => {
app.use(async (req, res, next) => {
// const start_datetime = getUnixTime(startOfWeek(startOfMonth(new Date())))
// req.events = await eventController._select(start_datetime, 100)
req.meta = await eventController._getMeta()
req.announcements = await announceController._getVisible()
if (!config.firstrun) {
const eventController = require('./api/controller/event')
const announceController = require('./api/controller/announce')
req.meta = await eventController._getMeta()
req.announcements = await announceController._getVisible()
}
req.firstrun = config.firstrun
next()
})
......
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