API
Local Environment variables
Kickstart using dotenv to setup environment variables for local development.
Below is the sample template inside api/.env
file.
WEBAPP_URL=http://localhost
WEBAPP_PORT=3000
API_URL=http://localhost
API_PORT=3333
FIREBASE_DATABASE_URL=YOUR_FIREBASE_DATABASE_URL
FIREBASE_PROJECT_ID=YOUR_FIREBASE_PROJECT_ID
FIREBASE_STORAGE_BUCKET=YOUR_FIREBASE_STORAGE_BUCKET
FIREBASE_PRIVATE_KEY=YOUR_FIREBASE_PRIVATE_KEY
FIREBASE_CLIENT_EMAIL=YOUR_FIREBASE_CLIENT_EMAIL
STRIPE_SECRET=YOUR_STRIPE_SECRET
STRIPE_WEBHOOK_SECRET=YOUR_STRIPE_WEBHOOK_SECRET
SENTRY_DSN=YOUR_SENTRY_DSN
NPM Custom Scripts
Kickstart API comes with several handly scripts for development or production.
npm run build - Compile typescript files into js filesnpm run clean - Remove the compiled js files, node_modules, and package/yarn lock filesnpm run dev - Running the API server in developmentnpm run fix - Fix the code syntax and issuesnpm run sort - Sort the package.json settingnpm run start - Running the API server in productionnpm run webhook - Running the stripe webhook mock server for sending webhook request locally
Start Stripe Webhooks Server Locally
In order to test our stripe webhook locally, we need to install Stripe CLI in our local machine.
Head over the stripe doc to install it.
Forward webhooks to the local server
stripe listen --forward-to localhost:3333/hooks
Record down the webhook signing secret
and paste it into the api/.env
file.
Start API server in local development
Install dependency packages first
npm install
Now compile typescript into js
npm run build
Start API server in local development
npm run dev
Setup Git Repo
Setup the local git repo
cd apigit initgit add .git commit -m "First commit"
Setup Github Repo
Login to Github and create a new repo.
Go back to the terminal to add GitHub repo to the origin and push the code to Github repo.
git remote add origin https://github.com/timshingyu/kickstart-demo-api.gitgit push -u origin master