diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-30 13:37:11 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-30 13:37:11 +0100 |
commit | 4f49137101a665f6a76bd8159a175a2aa680af96 (patch) | |
tree | 97f4956a2ae4642fefbd67f2839f4ab525e00821 | |
parent | 6cae49d26299b22ed879156ba5b8fb68a34e3713 (diff) | |
download | PeerTube-4f49137101a665f6a76bd8159a175a2aa680af96.tar.gz PeerTube-4f49137101a665f6a76bd8159a175a2aa680af96.tar.zst PeerTube-4f49137101a665f6a76bd8159a175a2aa680af96.zip |
Fix req accepts
-rw-r--r-- | server.ts | 4 | ||||
-rw-r--r-- | server/initializers/constants.ts | 3 | ||||
-rw-r--r-- | server/middlewares/activitypub.ts | 5 |
3 files changed, 8 insertions, 4 deletions
@@ -29,7 +29,7 @@ if (missed.length !== 0) { | |||
29 | throw new Error('Your configuration files miss keys: ' + missed) | 29 | throw new Error('Your configuration files miss keys: ' + missed) |
30 | } | 30 | } |
31 | 31 | ||
32 | import { API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' | 32 | import { ACCEPT_HEADERS, API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' |
33 | checkFFmpeg(CONFIG) | 33 | checkFFmpeg(CONFIG) |
34 | 34 | ||
35 | const errorMessage = checkConfig() | 35 | const errorMessage = checkConfig() |
@@ -129,7 +129,7 @@ app.use('/', staticRouter) | |||
129 | 129 | ||
130 | // Always serve index client page (the client is a single page application, let it handle routing) | 130 | // Always serve index client page (the client is a single page application, let it handle routing) |
131 | app.use('/*', function (req, res) { | 131 | app.use('/*', function (req, res) { |
132 | if (req.accepts('html')) { | 132 | if (req.accepts(ACCEPT_HEADERS) === 'html') { |
133 | return res.sendFile(path.join(__dirname, '../client/dist/index.html')) | 133 | return res.sendFile(path.join(__dirname, '../client/dist/index.html')) |
134 | } | 134 | } |
135 | 135 | ||
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 4f63cbb02..e3d779456 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -316,6 +316,8 @@ const CACHE = { | |||
316 | } | 316 | } |
317 | } | 317 | } |
318 | 318 | ||
319 | const ACCEPT_HEADERS = ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.concat('html', 'application/json') | ||
320 | |||
319 | // --------------------------------------------------------------------------- | 321 | // --------------------------------------------------------------------------- |
320 | 322 | ||
321 | const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->' | 323 | const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->' |
@@ -336,6 +338,7 @@ if (isTestInstance() === true) { | |||
336 | 338 | ||
337 | export { | 339 | export { |
338 | API_VERSION, | 340 | API_VERSION, |
341 | ACCEPT_HEADERS, | ||
339 | BCRYPT_SALT_SIZE, | 342 | BCRYPT_SALT_SIZE, |
340 | CACHE, | 343 | CACHE, |
341 | CONFIG, | 344 | CONFIG, |
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 485645720..c2ad18195 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts | |||
@@ -3,7 +3,7 @@ import { NextFunction, Request, RequestHandler, Response } from 'express' | |||
3 | import { ActivityPubSignature } from '../../shared' | 3 | import { ActivityPubSignature } from '../../shared' |
4 | import { isSignatureVerified, logger } from '../helpers' | 4 | import { isSignatureVerified, logger } from '../helpers' |
5 | import { database as db } from '../initializers' | 5 | import { database as db } from '../initializers' |
6 | import { ACTIVITY_PUB } from '../initializers/constants' | 6 | import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers/constants' |
7 | import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account' | 7 | import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account' |
8 | 8 | ||
9 | async function checkSignature (req: Request, res: Response, next: NextFunction) { | 9 | async function checkSignature (req: Request, res: Response, next: NextFunction) { |
@@ -37,7 +37,8 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) | |||
37 | 37 | ||
38 | function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { | 38 | function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { |
39 | return (req: Request, res: Response, next: NextFunction) => { | 39 | return (req: Request, res: Response, next: NextFunction) => { |
40 | if (!req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)) { | 40 | const accepted = req.accepts(ACCEPT_HEADERS) |
41 | if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) { | ||
41 | return next() | 42 | return next() |
42 | } | 43 | } |
43 | 44 | ||