For web applications, your program is an HTTP server that runs in the Native Node.js runtime. This topic outlines the specifications and guidelines you need to follow when you develop an HTTP server.
When developing an HTTP server locally, follow service specifications. For details, see Service specifications. In the Native Node.js runtime, veFaaS forwards requests to your HTTP server, and you can directly write the business logic of your function.
The following is a complete code example of developing an application using the Express framework.
Since you implement your own HTTP server in the Native Node.js runtime, you can define custom request processing logic in the HTTP server code. The following code demonstrates a simple request handler interface.
Configure a startup command
After you develop and compile the code, configure the startup command and listening port in the console when you create a serverless application hosting. In this example, the startup command is ./run.sh, and the listening port is 8000. Use environment variables
For Native Node.js functions, you can configure the environment variables required by the runtime of your function in the console and retrieve them in your code to implement function processing logic. veFaaS injects configured environment variables into the container where the function runs, and the program can read them using a built-in library for the programming language. For example, if the key of an environment variable is envKey, you can use the following code sample to read the environment variable.
- When developing a local code package, install the TypeScript package in package.json and add a script file.
- Add build.sh in addition to run.sh, and execute build.sh after development is complete.
- Run the following command to package the files into vefaas-native-typescript archive.
- Upload the ZIP package via the console and redeploy.