1.3.1 • Published 7 months ago

@znode/connect v1.3.1

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

@znode/connect

The Connect for Node.js

Usage

Koa

const Koa = require('koa');
const connect = require('@znode/connect');

const app = new Koa();

app.use(connect.koa.create('YOUR_SECRET_KEY'));

app.use((ctx) => {
  ctx.body = {
    user: connect.koa.getUser(ctx),
  };
});

app.listen(3000);

Express

const express = require('express');
const connect = require('@znode/connect');
const app = express();

app.use(connect.express.create('YOUR_SECRET_KEY'));

app.use((ctx) => {
  ctx.body = {
    user: connect.getUser(ctx),
  };
});

app.get('/', function (req, res) {
  res.json({
    user: connect.express.getUser(req),
  });
});

app.listen(3000);

Egg

// according: https://www.eggjs.org/basics/middleware

// app/middleware/connect.js
const connect = require('@znode/connect');

module.exports = (options, app) => {
  return async function connectMiddleware(ctx, next) {
    await connect.egg.create(options)(ctx, next);
  };
};

// use in plugin
// config/config.default.js
module.exports = {
  middleware: ['connect'],
};

// use in router
router.get('/', connect.egg.create('YOUR_SECRET_KEY'), controller.home.index);

// get user in controller
const user = connect.egg.getUser(ctx);
1.2.3

8 months ago

0.0.4

9 months ago

1.3.1

7 months ago

1.2.2

8 months ago

1.3.0

7 months ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago