Giter VIP home page Giter VIP logo

koa-hooks's Introduction

React.js hooks + koa.js 风格的轻量级 web 框架

code style: prettier

React.js hooks + koa.js 风格的轻量级 web 框架。

相关文章

安装

koa-hooks requires node v10 or higher for ES2015 and async function support.

$ npm install @zhengxs/koa-hooks --save

示例代码

hello,world

import { use, listen } from '@zhengxs/koa-hooks'

use(async ctx => {
  ctx.body = `hello,world`
})

listen(8080, () => {
  console.log('Liston http://127.0.0.1:8080')
})

路由匹配 和 重定向

import { Server } from 'http'

import { use, route, redirect, urlFor, listen } from '@zhengxs/koa-hooks'

route('product.detail', '/api/product/:id', ctx => {
  ctx.status = 200
  ctx.type = 'application/json'
  ctx.body = ctx.params
})

route('/api/user/info', () => {
  console.log('用户未登陆,跳转到登陆页')
  redirect(urlFor('login'))
})

route('login', '/login', ctx => {
  ctx.body = 'This login page.'
})

use(ctx => {
  ctx.body = `hello,world`
})

listen(8080, function onReady() {
  console.log('Liston http://127.0.0.1:8080')
})

启动项目

你需要安装 node.js 的版本为 nodejs >= 8.0

克隆此仓库后运行:

# 安装依赖,推荐使用 yarn 安装
$ npm install

# 启动示例
$ npm run dev

package.json 文件的 scripts 部分还有一些其他脚本可用.

版本发布

# 更新版本号,内置代码检查
$ npm version <new_version|major|minor|patch>

# 发布代码包,自动代码
$ npm publish

可使用 npm version --help 查看帮助信息

感谢

感谢这些开源贡献给予的灵感,以下排名不分先后。

koa-hooks's People

Contributors

zhengxs2018 avatar dependabot[bot] avatar

Stargazers

varHarrie avatar

Watchers

James Cloos avatar  avatar  avatar

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.