The SpicyChef backend is written entirely in node, using TypeScript, Express.js, Passport.js and other common node libraries.
The backend exposes an API, intended to be used with the SpicyChef client.
This backend server is configured by default to serve the API on yourdomain/api/
, and serve the bundled client application on all other paths(eg. yourdomain/*
).
- Download or clone the project
- Build the client
- The client should be bundled as described in client/README.md
- Put the public build directory somewhere accessible, and note the location in the env file
- Register a Google API application
- Follow Step 1 of this guide
- Note your client id and api secret
- Install npm dependencies
npm install
, alternativelynpm ci
for known exact versions.
- Populate the environment file as described below
- Use a randomly generated session secret
- Remember to insert your Google API details and callback URL
- Initialize the database
npm run initdb
- Start the development server
npm start
- Open the application in your browser
- The app should be running on
http://localhost:3000
when using the supplied dotenv
- The app should be running on
The following, modified for your needs, should be placed in .env
in this directory.
PORT=3001
CLIENT_BUILD_PATH='/../../client/public'
MYSQL_HOST=mysql.example.com
MYSQL_USER=spicychef
MYSQL_PASSWORD=spicychefpassword
MYSQL_DATABASE=spicychef
GOOGLE_OAUTH_ID=YOURGOOGLEID
GOOGLE_OAUTH_SECRET=YOURGOOGLESECRET
GOOGLE_CALLBACK_URL=http://YOURDOMAIN.com/api/auth/google/callback
SESSION_SECRET=RANDOMSECRETHERE
SESSION_SECURE_COOKIE=true
DEBUG=false
- Initialize and clear the database with
npm run initdb
- This will give an interactive prompt, verifying your database connection and creating the required tables.
- Requires that a database and user are already be created in your database server, and that the details are entered in
.env
- Import recipes from TheMealDB, see
npm run mealdb help
- Try
npm run mealdb getMeal 52814
- Try
npm run mealdb random
- Try
- We use jsdoc through better-docs to generate API docs.
- Rebuild the documentation with
npm run docs
- Read the docs on our site
- We strive to test all aspects of our application.
- Tests must be configured in
.env.test
- This configuration is similar to
.env
, but we recommend using a separate testing database - All data will be erased
- This configuration is similar to
- Run the tests with
npm test
- Show more verbose logs with
npm run test:debug
- Follow Development Setup steps 1-6
- Make a service, unit or supervisor configuration
- An init system or supervisor will help starting, stopping, managing and logging the application.
- Eg. write a basic systemd unit like this
- Configure a reverse proxy
- The application is on its own strictly HTTP
- Follow the guide and use letsencrypt or another TLS CA to sign HTTPS certificates
- Run the application with PORT=3000 or something similar, and only expose ports 80 and 443 through the proxy
- Eg. configure nginx like this
- Expose the service to the internet by forwarding ports to your host
- Verify connectivity by visiting your new web service