Giter Club home page Giter Club logo

midway-faas's Introduction

English | 简体中文

Midway FaaS 是一个用于构建 Node.js 云函数的 Serverless 框架,可以帮您在云原生时代更专注于产品开发,降低维护成本。

  • 跨云厂商:一份代码可以在多个云平台上快速部署,你不用担心产品被捆绑在一个云厂商上。
  • 代码重用:通过框架的依赖注入能力,代码逻辑的每个部分都是自然可复用的,可以快速轻松组合生成复杂的应用。
  • 传统迁移:通过框架的运行时扩展能力,可以将传统应用如 Egg.js、Koa、Express.js 等无缝迁移到各个云厂商。

文档

示例

当前已接入以下前端一体化示例。

React Vue
React Vue

加入社区

扫码加入即刻交流与反馈:

Join the chat at dingtalk

生态体系

Project Version Description
midway-faas faas-status 基于依赖注入适配多云平台的 Serverless 开发框架
runtime-engine runtime-engine-status 通用的基础 Serverless 运行时
serverless-fc-starter serverless-fc-starter-status 阿里云 FC 函数启动器
serverless-scf-starter serverless-scf-starter-status 腾讯云 SCF 函数启动器
midway midway-status 基于依赖注入面向未来的 Web 开发框架

社区合作伙伴

协议

Midway FaaS 基于 MIT licensed 协议开发.

About

Alibaba Open Source

midway-faas's People

Contributors

czy88840616 avatar echosoar avatar kurten avatar legendecas avatar lellansin avatar lxxyx avatar stone-jin avatar waitingsong avatar zqun 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

midway-faas's Issues

如何设置环境变量

在Fun 规范中可以通过 EnvironmentVariables 属性进行配置

  EnvironmentVariables:
          OSSEndpoint: oss-cn-hangzhou.aliyuncs.com
          BucketName: fun-local-test

在midway-faas中应该怎么实现类似的设置。

相关文档没有找到。

invoke 参数 data 传递不符合预期

./f.yml

service: serverless-hello-world

provider:
  name: aliyun

functions:
  index:
    handler: index.handler
    events:
      - http:
          method: post

package:
  artifact: code.zip

./test/index.test.ts

import { invoke } from '@midwayjs/serverless-invoke'
import * as assert from 'assert'
import { join } from 'path'

describe('/test/index.test.ts', () => {
  it('invoke', async () => {
    const result: any = await invoke({
      functionName: 'index',
      functionDir: join(__dirname, '../'),
      data: [
        {
          headers: { 'Content-Type': 'text/json' },
          method: 'POST',
          path: '/test',
          body: {
            name: 'test'
          }
        }
      ]
    })
    assert(/hello world/.test(result))
  })
})

./src/index.ts

import {
  FaaSContext,
  func,
  inject,
  provide,
  FunctionHandler
} from '@midwayjs/faas'

@provide()
@func('index.handler')
export class IndexService implements FunctionHandler {
  @inject()
  ctx: FaaSContext // context

  async handler() {
    /**
     * expect { 'Content-Type': 'text/json' }
     * actual { host: '127.0.0.1:55131','user-agent': 'curl/7.64.1'}
     */
    console.info(this.ctx.request.headers)

    /**
     * expect POST
     * actual GET
     */
    console.info(this.ctx.request.method)

    /**
     * expect /test
     * actual /
     */
    console.info(this.ctx.request.path)

    /**
     * expect { name: 'test' }
     * actual undefined
     */
    console.info(this.ctx.request.body)

    return 'hello world'
  }
}

funSpec.events is not iterable

functions:
rds:
handler: rds.handler
events:
- http:
method: get

我使用阿里云 api网关作为触发器的方式运行函数计算,http触发器不能和api网关同时存在。 当我在部署的过程中去掉events配置,会收到 funSpec.events is not iterable 错误。 请问有什么方法可以在部署的时候不配置触发器,否则每次部署完成我需要在控制台手动删除http触发器。

相关文档没有找到说明。

Cannot read property 'objectMode' of undefined

按照官方文档进行安装,会报这个错
Your Environment Information ---------------------------
Operating System: darwin
Node Version: 12.14.0
Framework Version: 1.62.0
Plugin Version: 3.3.0
SDK Version: 2.3.0
Components Core Version: 1.1.2
Components CLI Version: 1.4.0

Glossary of 《云端一体新前端工程模式在淘系前端的实践》

Serverless computing

中文:无服务器计算
详细解释:https://en.wikipedia.org/wiki/Serverless_computing

FaaS / Function as a service

中文:函数计算,我们下文亦称”云函数“
详细解释:https://en.wikipedia.org/wiki/Function_as_a_service

云端一体

意在将端侧和云函数(及其它云资源)高度融合,实现快速的互联网产品交付.

那句日语

あの日夢に見た風景、今だんだん現実にあらわれる
那日梦里见到的风景,如今渐渐在现实中出现了。

大中台 小前台

阿里巴巴集团提出的一种业务系统架构模式,这里我们亦有一些我们自己的解读。

业务中台能力

各种前台应用要用的业务中台能力,基本为机房内的 RPC 服务。

BaaS / Backend as a service

这里特指两点,除业务中台能力以外的。

  1. 各类云资源:如数据库、K/V、动态配置服务
  2. 高度垂直的技术产品:如 LBS、登录鉴权等

SLA / Service-level agreement

中文:服务等级协议

服务等级协议(SLA)最根本的形式是协议双方(服务提供者和用户)签订的一个合约或协议,主要保证了服务质量。

(业务)网关

有些业务场景需要引入一个业务网关,来处理业务相关的容灾、鉴权、安全等事项。

SSR / Server side rendering

中文:服务器端渲染

这里提到的特指,React 类前端组件在服务器端进行执行,最终通过 HTTP 协议交付标签语言(如 HTML)至用户代理。

静态页面托管服务

特指淘系一直在使用的一种静态 HTML 或 JS Bundle 的页面托管服务,基本上实现为一种 CDN 源站。提供多终端投放、模块化管理、和基础的模板语言能力(提供如时间判断等的相对静态逻辑能力)。

Assets CDN

通过 CDN 网络分发前端需要的静态资源的形式,如分发 JS、CSS、图片等。

一体化研发框架

特指基于 Midway FaaS 建立的多种场景的一体化研发框架,2020.3 会在本仓库与大家分享。

Rax SSR

Rax 是淘系前端的一个多端框架,https://github.com/alibaba/rax ,Rax SSR 就是它的服务器端渲染特性。

Monorepo

将多个子工程的组成部分,放到一个 Git 仓库的管理和开发方式。

https://en.wikipedia.org/wiki/Monorepo

Midway FaaS 社区路线图

其中的相关术语详见今年 D2 的分享。

https://github.com/d2forum/14th/blob/master/PPT/Serverless%20%E4%B8%8B%E5%87%BD%E6%95%B0%E5%BA%94%E7%94%A8%E6%9E%B6%E6%9E%84%E5%8D%87%E7%BA%A7--%E5%BC%A0%E6%8C%BA.pdf

金丝雀测试

英文:Canary release

Canary release is a technique to reduce the risk of introducing a new software version in production by slowly rolling out the change to a small subset of users before rolling it out to the entire infrastructure and making it available to everybody.

Troubleshooting

中文:问题排查解决的整个体系

因为中文一直没找到一个合适的词,一直沿用了英文。

Web IDE

在浏览器中的(云端)集成开发环境。

流量录制

录制异常流量,包括了函数的入参和下游调用的返回值,也包括环境(如时间、环境变量)等其它变量,可以在任何时刻回放某个特定请求。

全链路追踪

是指从端侧到最终的数据库,全链路追踪整个调用的情况。这类成熟产品包括 zipkin、jaeger 等。

单元化切流 / 冗余部署

我们的业务部署多个地区的多个可用区,大部分异常情况都只会发生在一个可用区,最好的恢复手段是将异常可用区摘除即可。

南北向出口

借用 Service Mesh 的概念,是指到公网互联网的出口。

FaaS 触发器

函数计算中的触发器概念,提供多种形式访问(或使用)函数。 我们应用比较多的是,RPC(应用间调用的形式)、HTTP 协议。

容器调度、函数 Infra

这一块之于公有云就是 Aliyun FC、AWS Lambda 一类的产品。 之于 K8S 体系,就是 KNative 一类的 Serverless 架构。

流量感知

函数计算一大特点是 Scale to 0 ,即没有调用的时候缩到 0 实例,有调用的时候快速拉起。 所以需要感知用户流量(如并发数、QPS),通过流量感知加上资源型指标实现自动容量托管。

D-FMEA

中文:设计阶段失效模式与影响分析

是一种工程设计阶段的一种质量管理方法论,最初由 NASA 提出。

阿里巴巴经典中间件架构

如 HSF、Tair、Diamond 这些产品,以前 Java 应用之间互访问协同的一些中间件产品。 基本等价于在阿里云上销售的 EDAS 产品。

https://www.aliyun.com/product/edas

防腐层

英文:Anti-corruption layer

在遗留系统和现代系统之间使用防腐层来隔离它们。该层转换两个系统之间的通信,允许遗留系统保持不变,同时可以避免损害现代应用程序的设计和技术方法。

configuration 业务自定义配置默认值无效

@Configuration({
  importConfigs: [
    './config/config.default',
    './config/config.local',
    './config/config.prod',
  ],
})

Configuration 部署后没有配置环境变量的情况应该是默认加载 config.prod ?

当前实际情况是必须配置一个环境变量才能生效。

本地运行 invoke 可以跳过缓存验证吗?

在项目中使用typeorm。

invoke本地运行会导致TypeORM的单例实例陷入混乱,无法重用链接。

应该和下面这个问题是类似的。

typeorm/typeorm#3427 (comment)

A long time has passed, and I finally had some time to actually look into this. It appears that this isn't really a problem in the AWS runtime at all, merely when using sls-offline to locally debug.

The reason (and fix) for that are mentioned in #2623 (which this issue is a duplicate of).

tl;dr: If you're using sls-offline, please invoke it with and none of the patches mentioned in this issue will be required. It's always been fine in the actual runtime (AWS) itself.--skipCacheInvalidation

What basically happens is that the singleton instance of TypeORM gets messed with when using the shared code runner from sls-offline.

@pleerock If more people confirm this is effective, I think you can close this issue.

ssr spec

本规范主要定义 ssr 特性,组件写法、目录结构以及 f.yml 文件扩展的编写规范。

扩展render配置

路由由f.yml的配置文件中,所以在f.yml增加render配置扩展,具体如下。

functions:
  home:
    handler: index.handler
    render:
      - component: src.home.index
      - layout: src.home.layout
      - fetch: src.home.fetch
      - mode: ssr | csr(默认ssr)
      - injectScript(自己改loyout更好)
          - runtime~Page.js
          - vendor.chunk.js
          - Page.chunk.js
      - injectCSS
          - Page.chunk.css
      - serverBundle: Page.server.js
    events:
      - http:
          path: /
          method:
            - GET
  news:
    handler: index.handler
    render:
      - component: src.news.index
      - layout: src.news.layout
      - fetch: src.news.fetch
      - mode: ssr | csr(默认ssr)
    events:
      - http:
          path: /
          method:
            - GET

多组件扩展支持

多组件支持是基于bigpipe的方式,首先写入layout布局,然后处理多个组件的组合逻辑,最终res.end即可。另外,组件上如果只有fetch方法,没有render方法也是没有问题的。写法有2种,具体如下。

component的值是数组,即串行方式

functions:
  news:
    handler: index.handler
    render:
      - component: 
        - src.news.index
        - src.news.index
        - src.news.index3
      - layout: src.news.layout
      - fetch: src.news.fetch
      - mode: ssr | csr(默认ssr)
    events:
      - http:
          path: /
          method:
            - GET

component的值是对象,即并行方式

functions:
  news:
    handler: index.handler
    render:
      - component: 
        a: src.news.index
        b: src.news.index
        c: src.news.index3
      - layout: src.news.layout
      - fetch: src.news.fetch
      - mode: ssr | csr(默认ssr)
    events:
      - http:
          path: /
          method:
            - GET

component支持无限嵌套,可以支持所有场景。

执行过程说明:

  • ssr模式时,采用bigpipe写入,最后red.end即可,前端不需要改造。
  • csr模式时,采用高阶组件封住,入口侧多个组件遍历,此处需要改造。

init project error and doc 404

image
when i init project getting an error that generate undefined error, The "path" argument must be of type string Received type undefined, and it seems don't have help option or --version。
Also the doc is not found

function handler = index.handler not found

v 0.2.66

npm test

Testing all *.test.js/ts...


  /test/index.test.ts
    1) invoke


  0 passing (3s)
  1 failing

  1) /test/index.test.ts
       invoke:
     Error: function handler = index.handler not found
      at AsyncFunction.<anonymous> (node_modules/@midwayjs/faas/src/starter.ts:144:13)
      at invokeHandlerWrapper (node_modules/@midwayjs/serverless-fc-starter/src/runtime.ts:55:22)
      at FCRuntime.invokeHandlerWrapper (node_modules/@midwayjs/runtime-engine/src/lightRuntime.ts:19:28)
      [use `--full-trace` to display the full stack trace]

f deploy command package not found

v 0.2.53 以上版本会存在部分f指令失效的问题。 例如:运行 f deploy 错误 :command package not found。

f test 和 f build 等指令又可以正常执行。

suikadeMac-mini:unikids-service-sms suika$ yarn add global @midwayjs/faas-cli

success Saved lockfile.
success Saved 8 new dependencies.

suikadeMac-mini:unikids-service-sms suika$ f deploy

command package not found

suikadeMac-mini:unikids-service-sms suika$ f test

Testing all *.test.js/ts...

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.