Express migrate to function calculation

barby-dalbosco-bzC3Emeb3-0-unsplash.jpg

First introduced in several important concepts under article appears:

Function calculates (Function Compute): function computing is an event-driven service, by computing function, users need to manage the operation of the servers, just write code and upload. Function calculates ready to computing resources, and is elastically stretchable run user code, and users only need to pay according to the actual code that runs resources consumed. More information function calculation reference .
Fun: Fun is a tool used to support Serverless application deployment, can help you easily manage function computing, API Gateway, logging services and other resources. It is through a resource configuration file (template.yml), help you develop, build, deploy operation. More Fun document reference .

Note: This tip requires Fun version 3.6.3 or greater.
2

Background Information

Express is based on a minimalist Node.js platform, flexible Web application development framework that provides a powerful set of features to help you create a variety of Web and mobile device applications.

Step one: Prepare the environment

The method described in this article, does not require installation Docker, you can only install Fun, the easiest way is to directly download an executable binary file.

  1. Fun is mounted to the machine. For details, see the installation documentation .
  2. Perform fun --versionchecks the installation was successful.

Step Two: Application Migration

  1. Execute the following command to create an Express project, please refer to Express the Application Generator , or you can follow the steps to create a simple official described the Hello world Example , Express project if this step is skipped.

    npx express-generator
    
  2. Execute the following command to enter the sample project or just created in your project.

    cd <project-name>
    
  3. Execute the following command to install depend.

    npm install
    
  4. Execute the following command to run the project.

  • MacOS, Linux platform to run the project:
    DEBUG=myapp:* npm start
    
  • windows platform to run the project:
    set DEBUG=myapp:* & npm start
    
  1. Run fun deploy -yto deploy the project to function calculation.
    Fun will automatically enter the deployment process.

    $fun deploy -y
    current folder is not a fun project.
    Generating /Users/txd123/Desktop/Express/bootstrap...
    Generating template.yml...
    Generate Fun project successfully!
    ========= Fun will use 'fun deploy' to deploy your application to Function Compute! =========
    using region: cn-qingdao
    using accountId: ***********3743
    using accessKeyId: ***********Ptgk
    using timeout: 60
    
    Collecting your services information, in order to caculate devlopment changes...
    
    Resources Changes(Beta version! Only FC resources changes will be displayed):
    ...  ...  ...  ...
       			trigger httpTrigger deploy success
       	function Express deploy success
    service Express deploy success
    
    Detect 'DomainName:Auto' of custom domain 'Domain'
    Request a new temporary domain ...
    The assigned temporary domain is 15795585-XXX.test.functioncompute.com,expired at 2020-04-12 10:46:25, limited by 1000 per day.
    Waiting for custom domain Domain to be deployed...
    custom domain Domain deploy success
    

    After the deployment is complete, you can see the success of the deployment of the log, generated for you function calculates the temporary domain name, you access the application just deployed directly through this temporary domain name.

    Note: temporary domain name is only used as a demonstration and development, with timeliness, For use as production, bind Ali cloud has been filed domain name, please refer to binding custom domain name .

to sum up

This article describes how to deploy Express applications to function calculation. Compared with traditional deployment methods, you can use a traditional key Express to deploy remote direct production. Skip the purchase of machinery and other steps, it is also have elastic stretch, according to the amount paid and free operation and maintenance characteristics.

" Alibaba Cloud native concern micro service, Serverless, container, Service Mesh and other technical fields, focusing cloud native popular technology trends, cloud native large-scale landing practice, most do understand the developer's native cloud technology circles."

Guess you like

Origin www.cnblogs.com/alisystemsoftware/p/12659466.html
Recommended