Skip to content

shfshanyue/serverless-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Apr 26, 2020
2060b01 · Apr 26, 2020

History

4 Commits
Apr 26, 2020
Apr 26, 2020
Apr 25, 2020
Apr 26, 2020
Apr 25, 2020
Apr 25, 2020
Apr 26, 2020
Apr 25, 2020
Apr 26, 2020
Apr 26, 2020
Apr 26, 2020
Apr 26, 2020
Apr 26, 2020

Repository files navigation

Serverless Http Component for Tencent Cloud

快速在腾讯云上部署 expresskoa 应用,并可以充分集成 typescriptbabel 等转译工具。本工具基于腾讯云的 tencent-framework

快速开始

根据我的模板进行创建,这是一个简单结合 koatypescript 的示例。关于本示例使用请移至 tencent-koa-ts

$ serverless install --url https://github.com/shfshanyue/serverless-template-zh/tree/master/tencent-koa-ts --name koa-function

部署到腾讯云

# 部署到腾讯云
$ sls
koa-function [████████████████████████████████████████] 100% | ETA: 0s | Speed: 314.98k/

  koa-app:
    functionName:        koa-function
    functionOutputs:
      ap-guangzhou:
        Name:        koa-function
        Runtime:     Nodejs10.15
        Handler:     http-handler.handler
        MemorySize:  128
        Timeout:     60
        Region:      ap-guangzhou
        Namespace:   default
        Description: This is a function created by serverless component
    region:              ap-guangzhou
    apiGatewayServiceId: service-dture22u
    url:                 https://service-dture22u-1257314149.gz.apigw.tencentcs.com/release/
    cns:                 (empty array)

  11s › koa-app › done

自定义配置

app:
  component: sls-component-http
  inputs:
    region: ap-guangzhou
    functionName: app-demo
    runtime: Nodejs10.15
    functionConf:
      timeout: 60
      memorySize: 128
    apigatewayConf:
      protocols:
        - https
      environment: release

更多配置参见 tencent framework configure

服务器框架

你可以从任意服务器框架中导出 HttpServer 作为入口文件,并在 package.json 中的 main 字段中标明入口文件位置。

因此你可以使用任意的转译工具,如 typescriptbabel,只需要注意在 package.json 中标明编译后入口文件位置。

Koa

const Koa = require('koa')

const app = new Koa()

app.use((ctx) => {
  ctx.body = 'hello, world'
})

module.exports = app

Express

const express = require('express')
const app = express()

// Routes
app.get(`/*`, (req, res) => {
  res.send('hello, world)
})

module.exports = app

注意点

  1. 如入口文件并非 index.js,请在 package.jsonmain 字段标明位置
  2. 严格区分 depdevDep,避免在部署时因为 node_modules 过大而造成速度过慢
  3. 如使用 typescript 等编译工具,请使用 inputs.exclude 排除源文件及编译工具

Releases

No releases published

Packages

No packages published