Fix req accepts

pull/143/head
Chocobozzz 2017-11-30 13:37:11 +01:00
parent 6cae49d262
commit 4f49137101
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 8 additions and 4 deletions

View File

@ -29,7 +29,7 @@ if (missed.length !== 0) {
throw new Error('Your configuration files miss keys: ' + missed) throw new Error('Your configuration files miss keys: ' + missed)
} }
import { API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' import { ACCEPT_HEADERS, API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants'
checkFFmpeg(CONFIG) checkFFmpeg(CONFIG)
const errorMessage = checkConfig() const errorMessage = checkConfig()
@ -129,7 +129,7 @@ app.use('/', staticRouter)
// Always serve index client page (the client is a single page application, let it handle routing) // Always serve index client page (the client is a single page application, let it handle routing)
app.use('/*', function (req, res) { app.use('/*', function (req, res) {
if (req.accepts('html')) { if (req.accepts(ACCEPT_HEADERS) === 'html') {
return res.sendFile(path.join(__dirname, '../client/dist/index.html')) return res.sendFile(path.join(__dirname, '../client/dist/index.html'))
} }

View File

@ -316,6 +316,8 @@ const CACHE = {
} }
} }
const ACCEPT_HEADERS = ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.concat('html', 'application/json')
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->' const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
@ -336,6 +338,7 @@ if (isTestInstance() === true) {
export { export {
API_VERSION, API_VERSION,
ACCEPT_HEADERS,
BCRYPT_SALT_SIZE, BCRYPT_SALT_SIZE,
CACHE, CACHE,
CONFIG, CONFIG,

View File

@ -3,7 +3,7 @@ import { NextFunction, Request, RequestHandler, Response } from 'express'
import { ActivityPubSignature } from '../../shared' import { ActivityPubSignature } from '../../shared'
import { isSignatureVerified, logger } from '../helpers' import { isSignatureVerified, logger } from '../helpers'
import { database as db } from '../initializers' import { database as db } from '../initializers'
import { ACTIVITY_PUB } from '../initializers/constants' import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers/constants'
import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account' import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account'
async function checkSignature (req: Request, res: Response, next: NextFunction) { async function checkSignature (req: Request, res: Response, next: NextFunction) {
@ -37,7 +37,8 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) {
return (req: Request, res: Response, next: NextFunction) => { return (req: Request, res: Response, next: NextFunction) => {
if (!req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)) { const accepted = req.accepts(ACCEPT_HEADERS)
if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) {
return next() return next()
} }