add to middlewares withCollection (unstable)
This commit is contained in:
1 parent
c77dc74965
commit
0c41bffb75
2 files changed
+24
-3
No files matched your search
@@ -0,0 +1,21 @@
|
|||||||
|
// import { MongoClient } from 'mongodb';
|
||||||
|
// const { connect, collection } = require('../../src/core/db')
|
||||||
|
// import {collection, connect} from '../core/db'
|
||||||
|
const core = require('../core/db')
|
||||||
|
|
||||||
|
// const client = new MongoClient(process.env.MONGODB_URI, { useNewUrlParser: true });
|
||||||
|
|
||||||
|
export const withCollection = handler => async (req, res) => {
|
||||||
|
await core.connect()
|
||||||
|
|
||||||
|
req.collection = core.collection
|
||||||
|
|
||||||
|
// if (!client.isConnected()) {
|
||||||
|
// return client.connect().then(() => {
|
||||||
|
// req.db = client.db('nextjsmongodbapp');
|
||||||
|
// return handler(req, res);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// req.db = client.db('nextjsmongodbapp');
|
||||||
|
return handler(req, res)
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
export const withMiddleware = handler => async (req, res) => {
|
import { withCollection } from './withCollection'
|
||||||
return handler(req, res);
|
|
||||||
};
|
export const withMiddleware = handler => withCollection(handler)
|
||||||
Reference in new issue
Block a user