3.6.1 • Published 7 months ago

gongo-server v3.6.1

Weekly downloads
12
License
MIT
Repository
github
Last release
7 months ago

gongo-server

Server(less) components for GongoJS fullstack data and auth

Copyright (c) 2020 by Gadi Cohen. MIT licensed.

npm CircleCI coverage MIT License

QuickStart

Assumes files placed in api directory are serverless functions (aka lambdas or cloud functions), like with Vercel, or pages/api in Next.JS.

api/gongoPoll.js:

const GongoServer = require('gongo-server/lib/serverless').default;
const Database = require('gongo-server-db-mongo').default;

const gs = new GongoServer({
  db: new Database('mongodb://localhost')
});

gs.db.Users.ensureAdmin('email@address', 'initialPassword');

gs.publish('test', db => db.collection('test').find());

module.exports = gs.express();

api/gongoAuth.js (optional):

const GongoServer = require('gongo-server/lib/serverless').default;
const GongoAuth = require('gongo-server/lib/auth').default;
const Database = require('gongo-server-db-mongo').default;

const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;

const gs = new GongoServer({
  db: new Database('mongodb://localhost')
});

const gongoAuth = new GongoAuth(gs, passport);

gongoAuth.use(new GoogleStrategy({
  clientID: process.env.GOOGLE_CLIENT_ID,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET,
  callbackURL: "http://localhost:3001/api/gongoAuth",
  passReqToCallback: true,
}, gongoAuth.passportVerify), {
  scope: 'email+profile'
});

module.exports = (req, res, next) => {
  passport.authenticate('google', gongoAuth.boundPassportComplete(req, res))(req, res, next);
}

Environment variables

  • NO_ENSURE=1

    By default, gongo will "ensure" some things in the database, like the admin user, oauth2 settings, etc. This happens every time the server is launched. For busy sites, setting this option to true will skip these checks, which will slightly reduce load on your database server every time a lambda cold starts.

3.6.1

7 months ago

3.4.0

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.5.0

2 years ago

3.2.0

2 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

5 years ago