current position:Home>Eoapi + vercel + serverless, deploy an API debugging tool

Eoapi + vercel + serverless, deploy an API debugging tool

2022-04-29 20:34:16Qin Yi

This is a super detailed example , After that, you will :

  • Speed of light Vercel、Serverless Functions
  • Get an exclusive one exactly like the picture API Tools

One 、 Concept of analytical

1. Serverless What is it? ?

Serverless Architecture is “ There is no server ” framework , It's a new way of Architecture , It is a revolutionary architecture model in the era of cloud computing .

Serverless The core idea of is to make the server as a computing resource no longer a resource that users pay attention to .

FaaS(Functions as a Service) Functions are services ,FaaS yes Serverless A form of calculation , This paper is about this form .

o , It's still in the clouds after reading, isn't it , No, no, keep looking .

2. Eoapi What is it? ?

An extensible open source API Tools , It's the picture at the beginning , You can use it to quickly debug API, You can experience Demo Address .

3. Vercel What is it? ?

Verce Is a site hosting platform , Be similar to Github Pages, You throw the source code of the web page up , Give you one back Web Service link , At the same time, it supports continuous integration , Can relate to Push、PR, Auto deploy after code submission .

Two 、 Quick start !

1. Fork Eoapi Warehouse

visit :github.com/eolinker/eo…

Fork After success, you can in your own Repositories notice eoapi.

2. To configure Vercel

visit :vercel.com/

After successful registration, click new project

To configure Vercel visit Github Project permissions , Choose Eoapi

configuration setup 、 Build commands and post build folders , After configuration, click the build button .

  • BUILD COMMAND:cd src/workbench/browser&&npm run build:web
  • OUTPUT DIRECTORY:src/workbench/browser/dist
  • INSTALL COMMAND:npm install&&cd src/workbench/browser&&npm install

Through this link, you can access your exclusive API Tools !

3、 ... and 、Serverless Funcions

1. Code

api There's a folder called unit.js The file of , When we deploy to the server , It becomes a HTTP Interface , One file, one interface , The interface address is api/<file_name>, Is it simple and rude ~

Serverless Functions Let's write interfaces as simple as pure functions

We just need exports A pure function , Through the first input parameter of the function req Get the request body , Re pass res.end() Return response body , You can quickly release a API.

api There's a folder called unit.js The file of , When we deploy to the server , It becomes a HTTP Interface , One file, one interface , The interface address is api/<file_name>, Is it simple and rude ~

Serverless Functions Let's write interfaces as simple as pure functions

We just need exports A pure function , Through the first input parameter of the function req Get the request body , Re pass res.end() Return response body , You can quickly release a API.

let _LibsFlowCommon = require('../src/workbench/node/request/unit.js');

let _LibsCommon = require('../src/workbench/node/request/libs/common.js');

module.exports = (req, res) => {
  try {

    let data = req.body.data;

    data.env = _LibsCommon.parseEnv(data.env);

    new _LibsFlowCommon.core().main(data, (tmpInputReport, tmpInputHistory) => {

      res.send(
        JSON.stringify('i am response')
      );

    });

  } catch (e) {
    console.error('unit.js', e, req.body);
  }
};
 Copy code 

2. How to debug locally

Vercel The official provided cli Tools

npm i -g vercel

vercel dev
 Copy code 

The rest can be debugged locally after being configured according to the command line instructions Serverless Functions 了

3、 ... and 、 Author's experience

I am a Eoapi A developer of ,Live Demo It is configured by using the above steps , If you are interested in the project , We welcome your continued attention to the project :github.com/eolinker/eo…

To be honest, I configured it for the first time Vercel I stepped on a lot of holes when I was , But overall, the experience is still very good .

Basically, all the websites I have in hand have been migrated to Vercel. except Eoapi, I also deployed my official website 、 A lottery program , It's cool .

Hey , You can also deploy and try , As a small assignment to test whether you have mastered the knowledge points .

Github Address :github.com/moshang-xc/…

Four 、 Reference material

copyright notice
author[Qin Yi],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/04/202204292034123911.html

Random recommended