mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
Add middleware/index.ts and remove default exports
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
6de6aa1d89
commit
e5961336b7
5 changed files with 10 additions and 4 deletions
|
@ -2,7 +2,7 @@ import { logger } from '../../logger'
|
||||||
import { errors } from '../../errors'
|
import { errors } from '../../errors'
|
||||||
import { NextFunction, Request, Response } from 'express'
|
import { NextFunction, Request, Response } from 'express'
|
||||||
|
|
||||||
export default function checkURI (req: Request, res: Response, next: NextFunction) {
|
export function checkURI (req: Request, res: Response, next: NextFunction): void {
|
||||||
try {
|
try {
|
||||||
decodeURIComponent(req.path)
|
decodeURIComponent(req.path)
|
||||||
next()
|
next()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { config } from '../../config'
|
import { config } from '../../config'
|
||||||
import { NextFunction, Request, Response } from 'express'
|
import { NextFunction, Request, Response } from 'express'
|
||||||
|
|
||||||
export default function version (req: Request, res: Response, next: NextFunction) {
|
export function codiMDVersion (req: Request, res: Response, next: NextFunction): void {
|
||||||
res.set({
|
res.set({
|
||||||
'CodiMD-Version': config.version
|
'CodiMD-Version': config.version
|
||||||
})
|
})
|
||||||
|
|
6
lib/web/middleware/index.ts
Normal file
6
lib/web/middleware/index.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { checkURI } from './checkURIValid'
|
||||||
|
import { codiMDVersion } from './codiMDVersion'
|
||||||
|
import { redirectWithoutTrailingSlashes } from './redirectWithoutTrailingSlashes'
|
||||||
|
import { tooBusy } from './tooBusy'
|
||||||
|
|
||||||
|
export { checkURI, codiMDVersion, redirectWithoutTrailingSlashes, tooBusy }
|
|
@ -1,7 +1,7 @@
|
||||||
import { NextFunction, Request, Response } from 'express'
|
import { NextFunction, Request, Response } from 'express'
|
||||||
import { config } from '../../config'
|
import { config } from '../../config'
|
||||||
|
|
||||||
export default function (req: Request, res: Response, next: NextFunction): void {
|
export function redirectWithoutTrailingSlashes (req: Request, res: Response, next: NextFunction): void {
|
||||||
if (req.method === 'GET' && req.path.substr(-1) === '/' && req.path.length > 1) {
|
if (req.method === 'GET' && req.path.substr(-1) === '/' && req.path.length > 1) {
|
||||||
const queryString: string = req.url.slice(req.path.length)
|
const queryString: string = req.url.slice(req.path.length)
|
||||||
const urlPath: string = req.path.slice(0, -1)
|
const urlPath: string = req.path.slice(0, -1)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { NextFunction, Request, Response } from 'express'
|
||||||
|
|
||||||
toobusy.maxLag(config.tooBusyLag)
|
toobusy.maxLag(config.tooBusyLag)
|
||||||
|
|
||||||
export default function tooBusy (req: Request, res: Response, next: NextFunction): void {
|
export function tooBusy (req: Request, res: Response, next: NextFunction): void {
|
||||||
if (toobusy()) {
|
if (toobusy()) {
|
||||||
errors.errorServiceUnavailable(res)
|
errors.errorServiceUnavailable(res)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue