Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@newstudios/koa2-middleware-ua

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@newstudios/koa2-middleware-ua

A middleware that set ua object for every incoming HTTP request in Koa2.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

koa2-middleware-ua

A middleware that generates ua object for every incoming HTTP request in Koa2.

How to develop

Using VSCode as deafult for debugger

# Using NPM
npm run example

# Using Yarn
yarn example

How to use

Installation

# Using NPM
$ npm install --save @xpc/koa2-middleware-ua

# Using Yarn
$ yarn add @xpc/koa2-middleware-ua

Usage

Use @xpc/koa2-middleware-ua as a middleware for a koa app. By default, it generates a unique uuid (v4) and exposes it on the response via the X-Request-ID header. The id is also saved as part of the ctx.req.idctx.request.idctx.id.

In the following example, the generated uuid is manually exposed on the body for debugging purposes:

const Koa = require('koa');
const { userAgent } = require('@xpc/koa2-middleware-ua');
const app = new Koa();

app.use(userAgent);
app.use(async ctx => {
  ctx.body = ctx.ua;
});

app.listen(3000);

打开浏览器访问 http://localhost:3000

{"_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"}

API

ctx.ua 对象包含

{
  _agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"
  isIOS: false
  isMobile: false
  isVmovierApp: false
  isWeixin: false
  isXpcApp: false
  xpcAppVersion: null
}

License

Provided under the terms of the MIT License

Copyright © 2020, xinpianchang.

Keywords

FAQs

Package last updated on 29 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc