This document describes how to quickly deploy a local Next.js SSR project to the cloud through an HTTP-triggered function.
Note:This document mainly describes how to deploy in the console. You can also complete the deployment on the command line. For more information, see Deploying Framework on Command Line.
Before using SCF, you need to sign up for a Tencent Cloud account and complete identity verification first.
webfunc
in the search box to filter function templates, select the Next.js template, and click Next. Note:As the Next.js framework needs to be rebuilt before each deployment, be sure to update the code locally and run
build
again before deploying.
The Node.js runtime environment has been installed locally.
Refer to Getting Started to install and initialize your Next.js project:
npx create-next-app
In the root directory, run the following command to directly start the service locally.
cd my-app && npm run dev
Visit http://localhost:3000
in a browser, and you can access the sample Next.js project locally as shown below:
You need to make simple modifications to the initialized project, so that the project can be quickly deployed through an HTTP-triggered function. The project transformation here is usually divided into the following two steps:
0.0.0.0:9000
.scf_bootstrap
bootstrap file.The detailed directions are as follows:
scf_bootstrap
bootstrap file in the project root directory and add the following content to it (which is used to start services and specify the bootstrap port):#!/var/lang/node12/bin/node
const { nextStart } = require('next/dist/cli/next-start');
nextStart([ '--port', '9000', '--hostname', '0.0.0.0' ])
Note
- Here is only a sample bootstrap file. Adjust the specific operations according to your actual business scenario.
- The sample uses the standard node environment path of SCF. When debugging locally, you need to change it to your local path.
777
or 755
is required for it to start normally. Below is the sample code:chmod 777 scf_bootstrap
After the deployment is completed, you can quickly access and test your web service in the SCF console and try out various features of SCF, such as layer binding and log management. In this way, you can enjoy the advantages of low cost and flexible scaling brought by the serverless architecture.
Was this page helpful?