Giter VIP home page Giter VIP logo

serverless-http-forward's Introduction

serverless-http-forward

阿里云 函数计算 HTTP 转发

说明

  • 转发 HTTP 请求

  • 链式调用的拦截器,允许跨域,路由权限控制等

不会转发的 HTTP Request Header 字段

  • host

不会转发的 HTTP Response Header 字段

  • connection
  • content-encoding
  • content-length
  • date
  • keep-alive
  • transfer-encoding

使用

git clone --depth=1 https://github.com/lisonge/serverless-http-forward.git
cd serverless-http-forward
pnpm i
pnpm run build

更改 config.toml 中的 forward_url 为要转发的 HTTP URL

然后把除了 .git 和 node_modules 的所有文件压缩成一个 any_name.zip

然后在 函数计算 香港地区 新建一个 node14 HTTP函数,配置函数入口 index.aliyunHandler

上传刚刚的压缩包即可部署,后续可以绑定自定义域名

用途

当 访问 https://i.songe.li

会调用 阿里云的 HTTP 函数(香港地区) 转发 此 HTTP 请求

到 (上海地区)服务器的 http://47.103.215.184:8888,然后转发回复

以 较低廉/零 的价格实现 无备案域名解析到 内地服务器

或者部署在 香港地区 转发海外api, 算是一种轻量级的翻墙方式

延迟

测试访问延迟

❯ curl -o /dev/null -s -w %{time_namelookup}:%{time_connect}:%{time_starttransfer}:%{time_total} 'http://47.103.215.184:8888'
0.000018:0.052224:0.252735:0.252797%
❯ curl -o /dev/null -s -w %{time_namelookup}:%{time_connect}:%{time_starttransfer}:%{time_total} 'https://i.songe.li'
0.115642:0.159558:0.509337:0.509372%

在只作为 API 接口的情况下 延迟在可接受范围内

注意

  • HTTP header 里 Set-Cookie 在单纯转发下将会出现问题

  • 是 HTTP 转发,不是 TCP 代理,所以不支持 Websocket

serverless-http-forward's People

Contributors

lisonge avatar

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.