This is a template of serverless fullstack application. It aims to be the simplest possible way to build a serverless fullstack application, including a Vue.js application on the front-end bundled with Parcel and back-end API.
This template includes:
-
Serverless RESTful API: Using @serverless/tencent-express component, it contains a Servelress Cloud Function and a single API Gateway endpoint.
-
Serverless website using Vue.js: @serverless/tencent-website, it deploys all static files to Cloud Object Storage.
Before all below steps, you should install Serverless Framework globally:
$ npm i serverless -g
Severless cli is very convenient, it can download templates in any github project which should contain serverless.yml
file.
$ serverless create --template-url https://github.com/yugasun/fullstack-application-postgres
Copy .env.example
file to .env
in project root:
Add the access keys of a Tencent CAM Role with AdministratorAccess
in the .env
file, like below:
# .env
TENCENT_SECRET_ID=xxx
TENCENT_SECRET_KEY=xxx
TENCENT_APP_ID=xxx
Install the NPM dependencies:
$ npm run bootstrap
Deploy via the serverless
command:
$ serverless
Use the --debug
flag if you'd like to learn what's happening behind the scenes:
$ serverless --debug
Notice: After deploy success, please copy the postgressql private url to
api/.env
file.
After your first deployment, you will be able to run the frontend locally and have it communicate to the live backend in the cloud.
$ cd frontend && npm run start
Because this project integrated cloud db connection, you should create a mysql instance on tencent cloud, please refer to official docs:
After you create a mysql instance, you should create a .env
file in api
folder, and set all required parameters like .env.example
.
MIT