scf-framework

1.0.4 • Public • Published

SCF Framework

简介

SCF Framework 是一个简单易用的工具,它可以帮助你将现有的 Express / Koa 框架构建的应用借助 API 网关 迁移到 腾讯云无服务云函数(Tencent Serverless Cloud Function)上。

开始使用

$ npm install scf-framework

Express 迁移

假设有如下 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)

支持的框架

Package Sidebar

Install

npm i scf-framework

Weekly Downloads

1

Version

1.0.4

License

Apache-2.0

Unpacked Size

20 kB

Total Files

6

Last publish

Collaborators

  • wescai