当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

koa-useragent

Koa user-agent middleware
授权协议 MIT License
开发语言 JavaScript
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 祖波光
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

koa-useragent

Fast Middleware exposing user-agent for koa.js based on express-useragent


Installation

$ npm install koa-useragent

Usage overview

const koa = require('koa');
const app = koa.app();
const { userAgent } = require('koa-useragent');

app.use(userAgent);

app.use(async (ctx, next) {
  console.log(require('util').inspect(ctx.userAgent));
});

app.listen(3000);

Typescript example

import Koa, { BaseContext } from 'koa';
import { userAgent, UserAgentContext } from 'koa-useragent';

const app = new Koa();

app.use(userAgent);

app.use<BaseContext, UserAgentContext>((ctx) => {
  console.log(require('util').inspect(ctx.userAgent));
});

app.listen(3000);

Module provides details such as the following:

{
  "isMobile":false,
  "isDesktop":true,
  "isBot":false,
  .....
  "browser":"Chrome",
  "version":"17.0.963.79",
  "os":"Windows 7",
  "platform":"Microsoft Windows",
  "source":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11"
}

Typescript support

From version 2.1.0 the library has rewritten in typescript. Definitions files distribute with source files.

From version 1.2.0, the library has type typescript definition file. You can install them from npm.

npm install --save-dev @types/koa-useragent

Author

Boris Ryabov (contact@bsryabov.ru).

Based on express-useragent by Aleksej Gordejev (aleksej@gordejev.lv).

License

(The MIT License)

Copyright (c) 2019 Boris Ryabov contact@bsryabov.ru

Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the'Software'), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:

The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Resources

  • 推荐使用ua-parser-js npm i ua-parser-js --save eg: const parser = require(‘ua-parser-js’); let ua = ctx.headers[‘user-agent’]; let ua_parser = new parser(ua); // 自己检查一些不常用的浏览器 if (/99Browser/.test

  • 目录 简介 应用 上下文(Context) 请求(Request) 响应(Response) 使用koa搭建一个简单的项目(下面的文档可以参考一下) koa2从搭建项目到实现API     这里梳理一下koa2项目简单的流程: app.js引入路由route router中绑定controllers中的方法 controllers处理发送的请求并调用modules中的sql方法 modules中引

  • 因为是koa中间件,所以最起码要先搭起一个koa服务。 先来介绍一下log4js 安装log4js模块 npm install log4js --save appenders 说白了就是配置打印输出源 type: "type":"console",即为控制台打印,多数用于开发测试。 "type":"file",表示日志输出为普通文件,在此种配置下日志会输出到目标文件夹的目标文件中,并会随着文件大小

  • 利用user-agent,判断请求是移动端的还是pc端的。 const checkPhone = (ctx) => { let userAgent = ctx.request.header['user-agent'].toLowerCase(); let pat_phone = /ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|window

 相关资料
  • Koa

    Koa art-template view render middleware. support all feature of art-template. Install npm install --save art-template npm install --save koa-art-template Example const Koa = require('koa'); const ren

  • koa

    koa是Express的下一代基于Node.js的web框架,目前有1.x和2.0两个版本。 历史 1. Express Express是第一代最流行的web框架,它对Node.js的http进行了封装,用起来如下: var express = require('express'); var app = express(); app.get('/', function (req, res) {

  • Koa

    Koa 是下一代的 Node.js 的 Web 框架。由 Express 团队设计。旨在提供一个更小型、更富有表现力、更可靠的 Web 应用和 API 的开发基础。 Koa可以通过生成器摆脱回调,极大地改进错误处理。Koa核心不绑定任何中间件,但提供了优雅的一组可以快速和愉悦地编写服务器应用的方法。 示例代码: var koa = require('koa');var app = koa();//

  • Koa - HelloWorld 以上便是全部了,我们重点来看示例,我们只注册一个中间件, Hello Worler Server: <?php $app = new Application(); // ... $app->υse(function(Context $ctx) { $ctx->status = 200; $ctx->body = "<h1>Hello Worl

  • koa-log4js A wrapper for log4js-node which support Koa logger middleware.Log message is forked from Express (Connect) logger file. Note This branch is use to Koa v2.x.To use Koa v0.x & v1.x, please ch

  • koa-rudy 环境 node -v >=6.9.0pm2 启动 npm install npm run dev 开发环境 npm run dev || test || prod 接口测试 npm run mocha 推荐开发工具 vscode 实现 支持 async/await MVC架构(middleware-view-controller) RESTful a

  • 学习 koa 源码的整体架构,浅析koa洋葱模型原理和co原理 1. 前言 你好,我是若川,微信搜索「若川视野」关注我,专注前端技术分享。欢迎加我微信ruochuan12,加群交流学习。 这是学习源码整体架构系列第七篇。整体架构这词语好像有点大,姑且就算是源码整体结构吧,主要就是学习是代码整体结构,不深究其他不是主线的具体函数的实现。本篇文章学习的是实际仓库的代码。 本文仓库地址:git clon

  • koa-seo SEO middleware for koa base on chrome-render, a substitute for prerender. Modern web app use technique like react.js vue.js which render html in browser, this lead to search engine can't crawl