UNPKG

scf-framework

Version:
123 lines (80 loc) 2.07 kB
# SCF Framework ## 简介 `SCF Framework` 是一个简单易用的工具,它可以帮助你将现有的 `Express` / `Koa` 框架构建的应用借助 [API 网关](https://cloud.tencent.com/product/apigateway) 迁移到 [腾讯云无服务云函数](https://cloud.tencent.com/product/scf)(Tencent Serverless Cloud Function)上。 ## 开始使用 ```shell $ npm install scf-framework ``` ### Express 迁移 假设有如下 `Express` 应用: ```js // app.js 'use strict' const express = require('express') const app = express() app.get('/', (request, response) => { response.end('hello world') }) app.litsen(8000) ``` 可以通过如下简单修改,迁移到 `SCF` 平台上: ```js // app.js 'use strict' const express = require('express') const app = express() app.get('/', (request, response) => { response.end('hello world') }) // comment out `listen` // exports your `app` // app.litsen(3000); module.exports = app ``` 将服务到入口文件修改为如下内容: ```js // index.js const app = require('./app') const scf = require('scf-framework') const server = scf.createServer(app) exports.main_handler = (event, context) => scf.proxy(server, event, context) ``` ### Koa 迁移 假设有如下 `Koa` 应用: ```js // app.js 'use strict' const Koa = require('koa') const app = new Koa() // response app.use(async ctx => { ctx.body = 'Hello World' }) app.litsen(3000) ``` 可以通过如下简单修改,迁移到 `SCF` 平台上: ```js // app.js 'use strict' const Koa = require('koa') const app = new Koa() // response app.use(async ctx => { ctx.body = 'Hello World' }) // comment out `listen` // exports your `app` // app.litsen(3000); module.exports = app ``` 将服务到入口文件修改为如下内容: ```js // index.js const app = require('./app') const scf = require('scf-framework') const server = scf.createServer(app) exports.main_handler = (event, context) => scf.proxy(server, event, context) ``` ## 支持的框架 - [express](https://expressjs.com) - [koa](https://koajs.com)