MosquitoTransport is a powerful tool that enables developers to persist and synchronize data between their MongoDB database and frontend applications. It offers a centralized and self-hosted solution for managing server infrastructure and data, along with robust authentication, real-time data updates, scalability, and cross-platform compatibility.
Under the hood, mosquito-transport uses Mongodb to store it data and express, socket.io for making request and jwt for signing authentication token, so make sure you have mongodb installed before using this package.
- Data Persistence and Synchronization ๐:
- Seamlessly persist and synchronize data between MongoDB and frontend applications, ensuring consistency across all clients.
- Self-Hosted Server ๐พ:
- Host your own server infrastructure, giving you full control over data storage, access, and management.
- User Authentication and Authorization ๐:
- Easily implement user authentication and authorization using JWT (JSON Web Tokens), providing secure access control to your application's resources.
- End-to-End Encryption ๐:
- Optionally enforce end-to-end encryption by allowing only encrypted data to be transmitted between client and server, ensuring data privacy and security.
- Real-Time Data Updates ๐จ:
- Enable real-time updates to keep data synchronized across all clients in real-time, providing a seamless user experience.
- Scalability and Performance ๐:
- Benefit from auto-scaling and high performance, allowing your application to handle varying workloads with ease.
- Cross-Platform Compatibility ๐ฑ:
- Compatible with React Native and web applications, allowing you to build cross-platform solutions with ease.
npm install mosquito-transport
or using yarn
yarn add mosquito-transport
import MosquitoTransportServer from "mosquito-transport";
import { MongoClient } from 'mongodb';
// create a mongodb instance
const dbInstance = new MongoClient('mongodb://127.0.0.1:27017', {
useNewUrlParser: true,
useUnifiedTopology: true
});
dbInstance.connect().then(() => {
console.log('connected to mongodb at');
}).catch(e => {
console.error('failed to connected to mongodb at');
});
// setup your server
const serverApp = new MosquitoTransportServer({
projectName: 'app_name',
port: 4534, // defaults to 4291
signerKey: 'random_90_hash_key_for_signing_jwt_tokens', // must be 90 length
accessKey: 'this_is_my_private_password', // keep this private if you don't provide databaseRules or storageRules
mongoInstances: {
// this is where user info and tokens is stored
admin: {
instance: dbInstance,
defaultName: 'ADMIN_DB_NAME'
},
// this will be the default db if no dbName was provided
default: {
instance: dbInstance,
defaultName: 'DEFAULT_DB_NAME'
}
},
databaseRules: ({ auth, collection, value, afterData, beforeData, operation, ...otherProps })=> new Promise((resolve, reject)=> {
// validate and authorize all incoming request to the database
if (collection === 'user') {
if (afterData && auth && auth.uid === value._id) {
resolve(); // allow read/write
} else reject('You don`t own this data, stay away'); // reject read/write
} else if (collection === 'other_paths') {
// blah, blah, other algorithm ...
}
}),
storageRules: ({...props})=> new Promise(resolve=> {
// validate and authorize all uploads/downloads
resolve(true) // handle read/write yourself here
}),
googleAuthConfig: {
clientID: 'your_google_authentication_clientID.apps.googleusercontent.com'
},
appleAuthConfig: {
...props
},
...otherProps
});
your server is now ready to be deploy on node.js! ๐. Now install any mosquito-transport client sdk and start making requests to the server.
- react-native-mosquito-transport for react native apps
- mosquito-transport-web for web platform
- mongodb-hack-middleware for random query hack and fulltext search hack
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT