Comments (13)
Another thought I had is that maybe the schema.js
file should simply export the raw JSON of the schema instead, and we can completely remove mongoose as a dependency and let the user import whichever version they want to use:
const ExpressBrute = require('express-brute');
const MongooseStore = require('express-brute-mongoose');
const BruteForceSchema = require('express-brute-mongoose/dist/schema');
const mongoose = require('mongoose');
const model = mongoose.model('bruteforce', new mongoose.Schema(BruteForceSchema));
const store = new MongooseStore(model);
module.exports = new ExpressBrute(store);
from express-brute-mongoose.
I created pull request #14 which should hopefully fix this issue. As a temporary workaround, you can just create the schema with the correct mongoose version yourself:
const ExpressBrute = require('express-brute');
const MongooseStore = require('express-brute-mongoose');
const BruteForceSchema = require('express-brute-mongoose/dist/schema');
const mongoose = require('mongoose');
const bruteForceSchema = new mongoose.Schema(//use our mongoose instance to create the schema
{
_id: { type: String },
data: {
count: Number,
lastRequest: Date,
firstRequest: Date
},
expires: { type: Date, index: { expires: '1d' } }
},
{ collection: 'bruteforce' }
);
const model = mongoose.model('bruteforce', bruteForceSchema);
const store = new MongooseStore(model);
module.exports = new ExpressBrute(store);
from express-brute-mongoose.
Same issue here, fixed it by replacing
var BruteForceSchema = require('express-brute-mongoose/dist/schema');
with
var BruteForceSchema = {
"_id": String,
"data": {
"count": Number,
"lastRequest": Date,
"firstRequest": Date
},
"expires": Date
}
from express-brute-mongoose.
Haven't seen that before. What does the code for your schema look like and what version of mongoose are you running in your app?
from express-brute-mongoose.
Full app code:
import express from 'express';
import ExpressBrute from 'express-brute';
import MongooseStore from 'express-brute-mongoose';
import BruteForceSchema from 'express-brute-mongoose/dist/schema';
import mongoose from 'mongoose';
let
app = express(),
model = mongoose.model('bruteforce', BruteForceSchema),
store = new MongooseStore(model),
bruteforce = new ExpressBrute(store);
app.post(
'/auth',
bruteforce.prevent,
(req, res, next) => {
res.send('Success!');
}
);
app.listen(3000, () => {
console.info('Express app listening on port 3000...');
});
Express v4.16.2
Mongo v3.6.1
Mongoose v5.0.1
e: Updated Mongoose to 5.0.2 and same error. Using nodemon & babel too, if that makes a difference.
from express-brute-mongoose.
Hm... I'm sorry, but I'm not able to repro that locally, even using all those module versions. Could you provide a link to the repository perhaps?
from express-brute-mongoose.
Just sent you a private repo invite on BB. Thanks for looking into this for me.
from express-brute-mongoose.
Alright, I pinned the problem down to the app locking to an outdated version of kareem, which is a dependency of mongoose. I have no idea why it's doing that though... I'll have more time to look into it later in the week.
from express-brute-mongoose.
I just ran into this myself... basically followed the standard install.
from express-brute-mongoose.
I ran into this problem aswell.
Fixed it by ensuring that mongoose is connected to my database before creating the brute storage.
from express-brute-mongoose.
Having the same problem. Checking if mongoose is connected does not work for me. Changing BruteForceSchema to the one provided in the readme and not "express-brute-mongoose/dist/schema", works.
from express-brute-mongoose.
I am getting this error. I tried waiting for mongoose to connect and changing the default schema to readme schema, but error persist.
Edit:
It works for me now. I had to make a new schema from scratch using the template in readme.
from express-brute-mongoose.
Thanks for all your guys' input (and sorry for the radio silence). I've implemented @noamichael's suggestion of removing the mongoose dependency from the package altogether and just expect the user to create the schema themselves using a raw json object exported by the package via express-brute-mongoose/dist/schema
. That's now live as of v1.1.0. Thanks and open a new issue if anyone's still having problems. 🍻
from express-brute-mongoose.
Related Issues (11)
- Did you try nesting Schemas? You can only nest using refs or arrays. HOT 2
- _id in the schema causing trouble? HOT 3
- Error using default example HOT 2
- IMHO found 1 high severity vulnerability HOT 1
- Any method to log the error when sending too many request?
- Update mongoose to the latest version HOT 1
- How to add custom data in schema
- error with mongoose 4.9.8. HOT 1
- Usage Question HOT 5
- Unhandled promise HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-brute-mongoose.