All Projects → HereSinceres → nodeMiddleWay

HereSinceres / nodeMiddleWay

Licence: other
node作为中间层调研项目

Programming Languages

javascript
184084 projects - #8 most used programming language
Pug
443 projects

Labels

Projects that are alternatives of or similar to nodeMiddleWay

Agile-Server
A simple, fast, complete Node.js server solution, based on KOA. 简单快速的 、性能强劲的、功能齐全的 node 服务器解决方案合集,基于 KOA。
Stars: ✭ 24 (+33.33%)
Mutual labels:  koa
route-decorators
ES7 decorators that simplify Koa and Express route creation
Stars: ✭ 71 (+294.44%)
Mutual labels:  koa
co-wechat-payment
Wechat payment lib for node.js koa framework.
Stars: ✭ 20 (+11.11%)
Mutual labels:  koa
vue-cms
VUE-CMS. Proudly Using ES7, Vue 2, Koa 2, Webpack 4, Babel 7 And Mocha
Stars: ✭ 16 (-11.11%)
Mutual labels:  koa
giog
It's based on githud issues and built with Vue 2.x, vue-router & vuex with server-side rendering by koa
Stars: ✭ 14 (-22.22%)
Mutual labels:  koa
react-isomorphic-bundle
React Redux Universal (isomorphic) bundle
Stars: ✭ 53 (+194.44%)
Mutual labels:  koa
redux-react-koa-isomorphic-counter-example
Isomorphic port of the redux counter app
Stars: ✭ 77 (+327.78%)
Mutual labels:  koa
lin-cms-koa-core
A simple and practical CMS implememted by koa
Stars: ✭ 42 (+133.33%)
Mutual labels:  koa
nfw
A jsonapi boilerplate for @nfw-core with mikro-orm
Stars: ✭ 23 (+27.78%)
Mutual labels:  koa
koa-router-version
Semantic Versioning routing for Koa
Stars: ✭ 19 (+5.56%)
Mutual labels:  koa
koaton
Koaton is a CLI tool that provides a nice starting point for full stack JavaScript Web development with Koa, Ember, and Node.js along with CaminateJS and WebSockets.
Stars: ✭ 28 (+55.56%)
Mutual labels:  koa
secondhand-deal
A campus secondhand trading system based on the vue.js + stylus + koa2 + sequelize ORM + mysql, and typescript is still learning to migrate.🍌
Stars: ✭ 21 (+16.67%)
Mutual labels:  koa
leizm-web
现代的 Web 中间件基础框架,完美支持 TypeScript,构建可维护的大型 Web 项目
Stars: ✭ 40 (+122.22%)
Mutual labels:  koa
slides
No description or website provided.
Stars: ✭ 27 (+50%)
Mutual labels:  koa
koa2-winston
koa2 version winston logger like express-winston
Stars: ✭ 37 (+105.56%)
Mutual labels:  koa
wx phoneBook
微信小程序-通讯录,一个非常简单的入门级的微信小程序
Stars: ✭ 23 (+27.78%)
Mutual labels:  koa
dashboard
📺🐝OpenPitrix UI
Stars: ✭ 29 (+61.11%)
Mutual labels:  koa
ibird
A lightweight and flexible web development framework.✨🚀✨
Stars: ✭ 74 (+311.11%)
Mutual labels:  koa
blog-backend
前后端分离实践----基于Koa2框架博客后端
Stars: ✭ 54 (+200%)
Mutual labels:  koa
graphql-typeorm-koa-workshop
Demo GraphQL API server
Stars: ✭ 36 (+100%)
Mutual labels:  koa

项目废弃,使用yog2,一个专注于 Node.js UI 中间层的应用框架。

初衷:我并不想改变团队原有开发模式,前端负责展现和界面路由,后端单纯负责API;

要解决的问题:Cancel changes

1.服务端渲染(部分界面【商品界面】需要使用服务器端渲染,但是管理类型界面并不需要服务器端渲染);

2.由于问题1的出现,所以我们需要服务器端渲染,需要控制路由,需要部分界面使用后端模板引擎。

3.当然我不想写两套api请求方式,Node.js可以搞定使用一套方案;

4.后台服务请求当然走代理服务。

方案选择:

1.koa2基础框架

2.axios--api请求服务

3.http-proxy--代理转发

其余日志处理,路由,后端模板引擎,异步语法自己选择了。 具体实现【仅供参考】:

1.代理转发【写koa2中间件】:匹配请求路由代理转发目标服务器

//中间件request_proxy.js
var httpProxy = require('http-proxy'); 
//EG:http://localhost:3001/rs-server-api/v1/goods/list
var proxy = new httpProxy.createProxyServer({
    target: 'https://stage.recovery-server.jiahuyunyi.com/',
    changeOrigin: true              // for vhosted sites, changes host header to match to target's host
});
var response_formatter = (ctx) => {
    proxy.web(ctx.req, ctx.res);
    ctx.body = ctx.res;
} 
var url_filter = (pattern) => {
    return async (ctx, next) => {
        var reg = new RegExp(pattern);
        try {
            //通过正则的url进行格式化处理
            if (reg.test(ctx.originalUrl)) {
                response_formatter(ctx);
            }
            await next();
        } catch (error) { 
            //继续抛,让外层中间件处理日志
            throw error;
        } 
    }
}
module.exports = url_filter;
const request_proxy = require('./middlewares/request_proxy');
//匹配路由/rs-server-api/v1/
app.use(request_proxy('^/rs-server-api/v1/'));

2.后端服务:当然ajax请求也是用这个js

import axios from "axios";
//没有权限直接跳转到登录界面
function fetchGoodsList() {
    return axios.get('http://localhost:3001/rs-server-api/v1/goods/list');
}
export default {
    fetchGoodsList: fetchGoodsList
}

在controller中调用服务

var router = require('koa-router')();
var Service = require('../services/index.js');
router.get('/', async function (ctx, next) {
  ctx.state = {
    title: await Service.fetchGoodsList().then((response) => {
      return JSON.stringify(response.data);
    })
  };
  await ctx.render('index', {
  });
})
module.exports = router;

最后项目DEMO地址,基于很多位前辈代码,仅仅加入代理转发 https://github.com/HereSinceres/nodeMiddleWay

koa2-boilerplate

A minimal boilerplate of koa v2.

NPM Version NPM Downloads

Installation

Both ways you can start:

fork this repo & git clone the repo
npm install koa2-boilerplate

Command

Setup

npm install

Develop

npm start

Test

npm test

Dependencies

  • Watcher and hot-reload: nodemon
  • Test:
  • Build: babel
    • tools: babel-register
    • presets: babel-preset-es2015-node5
    • plugins: transform-async-to-generator, syntax-async-functions
  • Lint: You can choose the lint tool that you prefer.

Reference

License

MIT © GeekPlux

登录信息存储在cookie(页面使用)

接口调用都加入head中

页面调用服务接口 从cookie取信息

Node调用服务接口 从cookie取信息

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].