import express from 'express' import { raw } from 'body-parser' import cookieParser from 'cookie-parser' import cors from 'cors' import config from 'config' //import serverRenderer from './middleware/renderer' import event from './middleware/event' import oembed from './middleware/oembed' import urlExpand from './middleware/urlexpand' import releases from './middleware/android' import { instance } from './middleware/mastodon' import path from 'path' import { webhook, webhookPath } from './durov' import { webfinger } from './middleware/webfinger' import { jsonMeta, nodeinfo, xmlMeta } from './middleware/host-meta' import { rememberMeParser } from './middleware/rememberme' // initialize the application and create the routes export const app = express() app.use(raw()) app.use(cors()) app.use(cookieParser()) app.use(rememberMeParser) const router = express.Router() router.post('/api/v2/sender', event) router.get('/api/v2/oembed', oembed) router.get('/api/v2/urlexpand', urlExpand) router.get('/api/apps/android/releases', releases) // Web Host Metadata router.get('/.well-known/host-meta', xmlMeta) router.get('/.well-known/host-meta.json', jsonMeta) // WebFinger router.get('/.well-known/webfinger', webfinger) // Nodeinfo router.get('/.well-known/nodeinfo', nodeinfo) // Mastodon API router.get('/api/v2/instance', instance) const durov_webhook = webhookPath() if (durov_webhook) { router.post(`/api/v2/${durov_webhook}`, webhook) } //router.use('^/$', serverRenderer) const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'public') // other static resources should just be served as they are router.use(express.static( STATIC_ROOT, { maxAge: '30d' }, )) //router.use('*', serverRenderer) app.use(router)