Git Product home page Git Product logo

z's Introduction

z

基于以下技术构建

  • Node.js & MidwayJS(EggJS)
  • TypeScript
  • Redis
  • MySQL 5.7 以上
  • Sequelize
  • TypeORM 底层还在进行大重构,暂时不适宜用于生产环境
  • Socket.io
  • GraphQL
  • ...

注意事项

因为 midwayjs 使用了 IoC 容器进行依赖解耦,所以开发方式会跟 eggjs 有些不一样,建议先阅读 midwayjs 官方文档Injection 文档

验证码模块使用了 node-canvas 库, 所以请先根据 node-canvas 文档 安装好相应的依赖

模块开发目录

开发目录为:src/app/modules/*

快速开始

请确保已经拉取项目到本地环境,并且安装配置好 Node/yarn

1、安装依赖

yarn

2、copy config 配置

cp src/config/config.example src/config/config.default.ts

然后修改对应的配置信息

3、执行数据库迁移

sequelize-cli 的数据库迁移并不好用,主要是它没办法定义多目录的 migration, 所以当前使用的是 typeorm 的数据库迁移功能

遇到出现 UnhandledPromiseRejectionWarning: QueryRunnerAlreadyReleasedError: Query runner already released. Cannot run queries anymore. 错误,请无需担心,这是 typeorm 的一个 bug, 不会影响迁移结果

yarn typeorm migration:run

4、运行

yarn dev

部署

更多请看 midway 部署

使用 docker 详见 docker 手册跟 Dockerfile

使用 pm2

pm2 start ecosystem.config.js

使用 egg-scripts

yarn start

辅助开发的 Cli 命令

对应代码目录: src/console

// 待补充

z's People

Contributors

atzcl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

z's Issues

Middleware/VerifyJwt.ts 中getToken的修改

/src/app/modules/User/Middleware/VerifyJwt.ts中

const [, token] = getToken.split(" ");  //这里是不是原本想split(".")拿payload?

是否应改为

const token = getToken; 

因为后面

const jwtResult = await ctx.helper.jwt({ secret: entryJwtSecret }).getCustomClaims(token);

getCustomClaims传入的应为token给verfiy第一个参数也是token。
我也只有这么改了才跑的通。

运行不起来,win

F:\work\z\node_modules\egg-core\lib\loader\mixin\middleware.js:66
throw new TypeError(Middleware ${name} not found);
^
TypeError: Middleware exceptions not found`

SkipPermissionCheck 获取不到用户token

遇到一个这样的场景 一个接口用户是否登陆都是可以访问的 用户登陆的话则返回用户信息 但是拆分成两个接口 前端调用不太现实。 是否可将SkipPermissionCheck 改为不跳过token验证, token不存在不报错, 存在即解token

error TS7016: Could not find a declaration file for module 'sequelize/lib/transaction'.

λ yarn typeorm migration:run
yarn run v1.17.3
$ ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:run
Error during migration run:
src/app/foundations/ORM/Model/BuildsQueries.ts:39:30 - error TS7016: Could not find a declaration file for module 'sequelize/lib/transaction'. 'C:/CODING_PROJECTS/midway_project/z/node_modules/sequelize/lib/transaction.js' implicitly has an 'any' type.
Try npm install @types/sequelize if it exists or add a new declaration (.d.ts) file containing declare module 'sequelize/lib/transaction';

39 import Transaction = require('sequelize/lib/transaction');

尝试 npm install @types/sequelize 和把vendor.d.ts拷贝到所在目录,都不行

ts error 7053

我就clone 了这个项目 复制了config.default.ts
yarn Dev
image
src/app/extend/helper.ts(240,11): error TS7053: Element implicitly has an 'any' type because expression of type '"pidField"' can't be used to index type 'unknown'.
Property 'pidField' does not exist on type 'unknown'.
src/app/extend/helper.ts(245,16): error TS2339: Property 'value' does not exist on type 'V'.
src/app/extend/helper.ts(245,24): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'unknown'.
No index signature with a parameter of type 'string' was found on type 'unknown'.
src/app/extend/helper.ts(246,16): error TS2339: Property 'label' does not exist on type 'V'.
src/app/extend/helper.ts(246,24): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'unknown'.
No index signature with a parameter of type 'string' was found on type 'unknown'.
src/app/extend/helper.ts(252,9): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'unknown'.
No index signature with a parameter of type 'string' was found on type 'unknown'.
src/app/extend/helper.ts(256,32): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'unknown'.
No index signature with a parameter of type 'string' was found on type 'unknown'.

error TS2339: Property 'validate' does not exist on type 'Request'.

运行 npm run dev

C:\CODING_PROJECTS\midway_server\node_modules\[email protected]@ts-node\src\index.ts:261
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/app/extend/context.ts(38,30): error TS2339: Property 'validate' does not exist on type 'Request'.

明明在VSC里按control也能跳到request.ts里的定义。不知道是不是lint的配置问题??

Service in class StockController is not valid in current context

请问这样是什么错误?
Service in class StockController is not valid in current context

在controller

import { controller, provide, inject, get, post, put, del } from "midway";
import { Controller } from "@app/foundations/Bases/BaseController";
import { StockStockService } from "../Services/Stock";
@provide()
@controller("/stocks") // , { middleware: ["verifyJWTMiddleware"] as GlobalMiddlewareNames }
export class StockController extends Controller {
  @inject("Service")
  service!: StockStockService;

  @get("/")
  async index() {
    const result = await this.service.paginate(this.request);

    return this.setStatusData(result.data)
      .setStatusTotal(result.count)
      .succeed();
  }

  @post("/")
  async store() {
    const result = await this.service.store(this.request._body());

    return this.setStatusData(result).succeed();
  }

  @put("/:id")
  async update() {
    const result = await this.service.update(this.request._query("id"), this.request._body());

    return this.setStatusData(result).succeed();
  }

  @del("/:id")
  async destroy() {
    return this.setStatusData(await this.service.delete(this.ctx.params.id)).succeed();
  }
}

在Service

import { provide } from "midway";
import { Service } from "@app/foundations/Bases/BaseService";

import { StockStockModel } from "../Models/Stock";

// 在容器的 id 名称
export const SERVICE_PROVIDE = "StockStockService";

@provide(SERVICE_PROVIDE)
export class StockStockService extends Service {
  model() {
    return StockStockModel;
  }
}

在Model

import { Table, Column } from "sequelize-typescript"; // DataType,
import { BaseModel, DefaultColumns } from "@app/foundations/ORM/Model";

// const { STRING } = DataType;
import { DEFAULT_STATUS } from "@/app/constants/Global";
// import { Timestamp } from "typeorm";

@Table({
  modelName: "stocks",
})
@DefaultColumns
export class StockStockModel extends BaseModel<StockStockModel> {
  //
  @Column
  code!: string;

  @Column
  display_name!: string;

  @Column
  name!: string;

  @Column
  start_date!: string;

  @Column({ allowNull: true })
  end_date: string;

  @Column
  type!: string;

  @Column({ allowNull: true })
  parent!: string;

  @Column({ defaultValue: DEFAULT_STATUS.NORMAL })
  status!: number;
}

await app.createBcrypt这个函数方法没办法保存数据库

{
            // 开启软删除
            paranoid: true,
            // 修改器
            setterMethods: {
                async password(value: any) {
                    // 加密密码
                    (this as any).setDataValue('password',await app.createBcrypt(value))
                },
            },
        })

这个密码没办法存数据库,如果去掉了await app.createBcrypt这个,也能保存数据库。这为什么?

多模块里面至少一个services怎么样才能挂载Context?

你好,我看了你写的这个项目挺好,值得我参考学习,但是我这几天遇到了有问题,想请你帮忙看一下怎么解决这个问题,谢谢

问题描述
1、建了app/modules,modules都是mvc模式的,modeules里面有对应业务逻辑的文件,比如登录,用户管理,权限管理,角色管理。。。等,每个文件都有对应的路由配置,基于egg-router-plus的实现方法。

2、举例在app/modules/users,users里面分别有controllers文件夹,services文件夹,router配置文件。在controllers上请求访问到ctx.modules.users.services.index(),但是访问这个ctx.modules结果是undefined。

操作问题:
eggjs如何将这个定义模块挂载在context上,让任何一个模块里的controllers上请求访问services,services即是ctx.modules.users.services。

SkipPermissionCheck.add 参数为数组时有bug

static add(path: string | string[]) {
isArr(path) ? path.forEach(this.addRoutePaths) : this.addRoutePaths(path);
}
应该改为

static add(path: string | string[]) {
isArr(path)
? path.forEach((url) => this.addRoutePaths(url))
: this.addRoutePaths(path);
}

migration模板里三个引用无效?

在模板生成的migration里有三个引用,这三个文件没有找到噢,请问是在哪?

import UuidPrimary from '@/app/foundations/migrations/UuidPrimary';
import Timestamps from '@/app/foundations/migrations/Timestamps';
import SoftDeletes from '@/app/foundations/migrations/SoftDeletes';

如何使用baseModel 的 static hidden字段

我在查询数据后,数据中出现了created_at, createdAt, updated_at, updatedAt, 我希望使用Model的hidden字段隐藏这些。 但是我添加了hidden = [‘createdAt’,'updatedAt'] 好像并不顶用

数据库迁移报错

image
$ ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:run
Error during migration run:
src/app/foundations/ORM/Model/BuildsQueries.ts:43:30 - error TS7016: Could not find a declaration file for module 'sequelize/lib/transaction'. 'D:/midway/ts-midway/node_modules/sequelize/lib/transaction.js' implicitly has an 'any' type.
Try npm install @types/sequelize if it exists or add a new declaration (.d.ts) file containing declare module 'sequelize/lib/transaction';

43 import Transaction = require("sequelize/lib/transaction")

报错 TSError: [egg-core] load file: src\config\config.default.ts, error: ⨯ Unable to compile TypeScript:

之前的版本没问题 更新到最新版后就报这个错

TSError: [egg-core] load file: src\config\config.default.ts, error: ⨯ Unable to compile TypeScript:
src/config/config.default.ts(79,9): error TS7018: Object literal's property 'connectionMiddleware' implicitly has an 'any[]' type.
src/config/config.default.ts(80,9): error TS7018: Object literal's property 'packetMiddleware' implicitly has an 'any[]' type.
src/config/config.default.ts(83,9): error TS7018: Object literal's property 'connectionMiddleware' implicitly has an 'any[]' type.
src/config/config.default.ts(84,9): error TS7018: Object literal's property 'packetMiddleware' implicitly has an 'any[]' type.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.