npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aipeli/midway-log2db

v1.0.9

Published

Recode access api to db based on MidwayJS(koa) v3.x

Downloads

15

Readme

🏠 项目主页

记录API访问日志并保存到数据中,自动识别来访问者IP地址位置、用户代理信息等

Recode access api to db based on MidwayJS(koa) v3.x

📦 环境要求

  • midway >=3.x

🛠️ 安装

pnpm install @aipeli/midway-log2db

✍️ 用法

import { Crud, BaseController } from '@aipeli/midway-crud';
import { Log2DbService } from '@aipeli/midway-log2db';
import { Get, Inject } from '@midwayjs/decorator';
import { Context } from '@midwayjs/koa';

@Crud('/log2db')
export class ShopAdminLog2DbController extends BaseController {
  @Inject()
  ctx: Context;
  @Inject()
  log2db: Log2DbService;
  
  /**
   * 保存日志记录
   * http://127.0.0.1:7001/admin/shop/log2db/record
   * @returns 返回保存日志记录的ID
   */
  @Get('/record')
  async record() {
    const result_data = await this.log2db.record(
      this.ctx,
      this.ctx.url.split('?')[0],
      this.ctx.req.method === 'GET'
        ? this.ctx.request.query
        : this.ctx.request.body,
      this.ctx.admin ? this.ctx.admin.userId : 1,
      this.ctx.request.header['user-agent']
    );
    return { success: true, message: 'OK', data: result_data };
  }

  /**
   * 清除日志
   * http://127.0.0.1:7001/admin/shop/log2db/clear
   */
  @Get('/clear')
  async clear() {
    // 清除全部日志
    await this.log2db.clear();
    await this.log2db.clear(0, true);
    // 清除3天前的日志
    await this.log2db.clear(3, false);

  }
}

🧪 配置

配置 config/config.default.ts

import { MidwayConfig } from '@midwayjs/core';

export default {
  // use for cookie sign key, should change to your own and keep security
  keys: '1644208064112_2754',
  koa: {
    port: 7001,
  },
  orm: {
    /**
     * 单数据库实例
     */
    default: {
      type: 'mysql',
      host: '127.0.0.1',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'midway_crud',
      synchronize: true, // 如果第一次使用,不存在表,有同步的需求可以写 true
      logging: false,
    },
  },
  log2db: {
    ipdb: '/ipdb/ipipfree.ipdb'
  }
} as MidwayConfig;

配置 /configuration.ts

import { Configuration, App } from '@midwayjs/decorator';
import * as koa from '@midwayjs/koa';
import * as validate from '@midwayjs/validate';
import * as info from '@midwayjs/info';
import { join } from 'path';
import * as crud from '@aipeli/midway-crud';
import * as log2db from '@aipeli/midway-log2db';
@Configuration({
  imports: [
    koa,
    validate,
    crud,
    log2db,
    {
      component: info,
      enabledEnvironment: ['local'],
    },
  ],
  importConfigs: [join(__dirname, './config')],
})
export class ContainerLifeCycle {
  @App()
  app: koa.Application;

  async onReady() {

  }
}

🧑 开发人员

  • 🧑 aipeli

🤝 贡献

欢迎投稿、问题和功能请求! issues 地址.

⭐️ 支持

如果项目对你有帮助,请给我一个 start⭐️ 吧!

📝 License

Copyright © 2022 aipeli. This project is MIT licensed.


This README was generated with ❤️ by fast-readme