add withMiddleware for all api routes. Now it do nothing
This commit is contained in:
1 parent
cd7536f74f
commit
95c8369df2
16 files changed
+48
-30
No files matched your search
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Album from '../../../src/core/Album'
|
import Album from '../../../src/core/Album'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const id = req.query.album
|
const id = req.query.album
|
||||||
@@ -15,4 +16,4 @@ export default async (req, res) => {
|
|||||||
error: `Album ${id} not found`
|
error: `Album ${id} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Album from '../../../src/core/Album'
|
import Album from '../../../src/core/Album'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const data = await Album.find({}, { sort: { date: -1 } })
|
const data = await Album.find({}, { sort: { date: -1 } })
|
||||||
@@ -15,4 +16,4 @@ export default async (req, res) => {
|
|||||||
error: `Article not found`
|
error: `Article not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import { findArticles } from '../../../src/api/articles'
|
import { findArticles } from '../../../src/api/articles'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const { query } = req
|
const { query } = req
|
||||||
@@ -18,4 +19,4 @@ export default async (req, res) => {
|
|||||||
error: `Article ${id} not found`
|
error: `Article ${id} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Article from '../../../src/core/Article'
|
import Article from '../../../src/core/Article'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const data = await Article.find({})
|
const data = await Article.find({})
|
||||||
@@ -17,4 +18,4 @@ export default async (req, res) => {
|
|||||||
error: `Not found`
|
error: `Not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Document from '../../../src/core/Document'
|
import Document from '../../../src/core/Document'
|
||||||
import { encodeFile } from '../../../src/api/files'
|
import { encodeFile } from '../../../src/api/files'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const id = req.query.document
|
const id = req.query.document
|
||||||
@@ -16,4 +17,4 @@ export default async (req, res) => {
|
|||||||
error: `Document ${id} not found`
|
error: `Document ${id} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Document from '../../../src/core/Document'
|
import Document from '../../../src/core/Document'
|
||||||
import { encodeFile } from '../../../src/api/files'
|
import { encodeFile } from '../../../src/api/files'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const documents = await Document.find({hidden: false})
|
const documents = await Document.find({hidden: false})
|
||||||
@@ -20,4 +21,4 @@ export default async (req, res) => {
|
|||||||
error: `Documents not found`
|
error: `Documents not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Document from '../../../src/core/Document'
|
import Document from '../../../src/core/Document'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const data = await Document.find({})
|
const data = await Document.find({})
|
||||||
@@ -17,4 +18,4 @@ export default async (req, res) => {
|
|||||||
error: `Not found`
|
error: `Not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
import { connect } from '../../src/core/db'
|
import { connect } from '../../src/core/db'
|
||||||
import Image from '../../src/core/Image'
|
import Image from '../../src/core/Image'
|
||||||
import { encodeImage } from '../../src/api/image'
|
import { encodeImage } from '../../src/api/image'
|
||||||
|
import { withMiddleware } from '../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const file = req.query.file
|
const file = req.query.file
|
||||||
@@ -16,4 +17,4 @@ export default async (req, res) => {
|
|||||||
error: `Image ${file} not found`
|
error: `Image ${file} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
+3
-2
@@ -2,8 +2,9 @@ import { connect } from '../../src/core/db'
|
|||||||
import Page from '../../src/core/Page'
|
import Page from '../../src/core/Page'
|
||||||
import { getPathWithNoTrailingSlash } from '../../src/lib/url'
|
import { getPathWithNoTrailingSlash } from '../../src/lib/url'
|
||||||
import { encodePage } from '../../src/api/page'
|
import { encodePage } from '../../src/api/page'
|
||||||
|
import { withMiddleware } from '../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const page = getPathWithNoTrailingSlash(req.query.page)
|
const page = getPathWithNoTrailingSlash(req.query.page)
|
||||||
@@ -17,4 +18,4 @@ export default async (req, res) => {
|
|||||||
error: `Image ${page} not found`
|
error: `Image ${page} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Page from '../../../src/core/Page'
|
import Page from '../../../src/core/Page'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const items = await Page.find({})
|
const items = await Page.find({})
|
||||||
@@ -16,4 +17,4 @@ export default async (req, res) => {
|
|||||||
error: `Article ${id} not found`
|
error: `Article ${id} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Page from '../../../src/core/Page'
|
import Page from '../../../src/core/Page'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const data = await Page.find({})
|
const data = await Page.find({})
|
||||||
@@ -17,4 +18,4 @@ export default async (req, res) => {
|
|||||||
error: `Not found`
|
error: `Not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Teacher from '../../../src/core/Teacher'
|
import Teacher from '../../../src/core/Teacher'
|
||||||
import { encodePerson } from '../../../src/api/persons'
|
import { encodePerson } from '../../../src/api/persons'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const id = req.query.person
|
const id = req.query.person
|
||||||
@@ -16,4 +17,4 @@ export default async (req, res) => {
|
|||||||
error: `Article ${id} not found`
|
error: `Article ${id} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -2,8 +2,9 @@ import { connect } from '../../../src/core/db'
|
|||||||
import Teacher from '../../../src/core/Teacher'
|
import Teacher from '../../../src/core/Teacher'
|
||||||
import { prioritySort } from '../../../src/lib/sort'
|
import { prioritySort } from '../../../src/lib/sort'
|
||||||
import { encodePerson } from '../../../src/api/persons'
|
import { encodePerson } from '../../../src/api/persons'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const order = [
|
const order = [
|
||||||
@@ -29,4 +30,4 @@ export default async (req, res) => {
|
|||||||
error: `Article ${id} not found`
|
error: `Article ${id} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../../src/core/db'
|
import { connect } from '../../../src/core/db'
|
||||||
import Teacher from '../../../src/core/Teacher'
|
import Teacher from '../../../src/core/Teacher'
|
||||||
|
import { withMiddleware } from '../../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const data = await Teacher.find({})
|
const data = await Teacher.find({})
|
||||||
@@ -17,4 +18,4 @@ export default async (req, res) => {
|
|||||||
error: `Not found`
|
error: `Not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import { connect } from '../../src/core/db'
|
import { connect } from '../../src/core/db'
|
||||||
import { findSchedule } from '../../src/core/schedule'
|
import { findSchedule } from '../../src/core/schedule'
|
||||||
|
import { withMiddleware } from '../../src/middlewares/withMiddleware'
|
||||||
|
|
||||||
export default async (req, res) => {
|
export default withMiddleware(async (req, res) => {
|
||||||
await connect()
|
await connect()
|
||||||
|
|
||||||
const period = req.query.period
|
const period = req.query.period
|
||||||
@@ -16,4 +17,4 @@ export default async (req, res) => {
|
|||||||
error: `Schedule ${period}:${semester} not found`
|
error: `Schedule ${period}:${semester} not found`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export const withMiddleware = handler => async (req, res) => {
|
||||||
|
return handler(req, res);
|
||||||
|
};
|
||||||
Reference in new issue
Block a user