1.0.4 • Published 6 years ago
scf-framework v1.0.4
SCF Framework
简介
SCF Framework 是一个简单易用的工具,它可以帮助你将现有的 Express / Koa 框架构建的应用借助 API 网关 迁移到 腾讯云无服务云函数(Tencent Serverless Cloud Function)上。
开始使用
$ npm install scf-frameworkExpress 迁移
假设有如下 Express 应用:
// app.js
'use strict'
const express = require('express')
const app = express()
app.get('/', (request, response) => {
response.end('hello world')
})
app.litsen(8000)可以通过如下简单修改,迁移到 SCF 平台上:
// 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将服务到入口文件修改为如下内容:
// 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 应用:
// 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 平台上:
// 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将服务到入口文件修改为如下内容:
// 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)