diff --git a/.env-sample b/.env-sample index a7686d87..68158abb 100644 --- a/.env-sample +++ b/.env-sample @@ -22,7 +22,9 @@ FIRE_API_KEY={firebase key} FIRE_DOMAIN={firebase domain} FIRE_PROJECT_ID={firebase project id} -# If using mysql, enter your config here +# If using mysql, You can use a database URL or enter multiple configuration variables. Comment out the variables you don't use by adding the `#` character to the beginning of the line. + +# DATABASE_URL={mysql://db_address} MYSQL_HOST={mysql host} MYSQL_DATABASE={mysql database name} diff --git a/README.md b/README.md index 42223e93..e93a78f0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This starter app includes all the files necessary to get started with a basic, hello world app. This app uses NextJS, BigDesign, Typescript, and React. -## Running the app +## Running the app in development To get the app running locally, follow these instructions: @@ -82,3 +82,14 @@ npm run dev > If `ngrok` expires, update the callbacks in steps 4 and 7 with the new `ngrok_url`. You can learn more about [persisting ngrok tunnels longer (ngrok)](https://ngrok.com/docs/getting-started/#step-3-connect-your-agent-to-your-ngrok-account). 11. Consult our developer documentation to [install and launch the app](https://developer.bigcommerce.com/api-docs/apps/quick-start#install-the-app). + +## Production builds + +In production, you must build and run optimized version of the code. Use the following commands to get started: + +> When you run the `start` script, specify a port number using the `-p` flag. Otherwise, the process will fail. + +```shell +npm run build +npm run start -p 3000 +``` diff --git a/lib/dbs/mysql.ts b/lib/dbs/mysql.ts index 5991b0ce..568bd5ba 100644 --- a/lib/dbs/mysql.ts +++ b/lib/dbs/mysql.ts @@ -1,4 +1,4 @@ -import { createPool, PoolOptions } from 'mysql2'; +import mysql, { PoolOptions } from 'mysql2'; import { promisify } from 'util'; import { SessionProps, StoreData } from '../../types'; @@ -10,10 +10,10 @@ const MYSQL_CONFIG: PoolOptions = { ...(process.env.MYSQL_PORT && { port: Number(process.env.MYSQL_PORT) }), }; -// For use with Heroku ClearDB +// For use with DB URLs // Other mysql: https://www.npmjs.com/package/mysql#pooling-connections -const dbUrl = process.env.CLEARDB_DATABASE_URL; -const pool = dbUrl ? createPool(dbUrl) : createPool(MYSQL_CONFIG); +const dbUrl = process.env.DATABASE_URL; +const pool = dbUrl ? mysql.createPool(dbUrl) : mysql.createPool(MYSQL_CONFIG); const query = promisify(pool.query.bind(pool)); // Use setUser for storing global user data (persists between installs) diff --git a/scripts/db.js b/scripts/db.js index e69a6193..14eb753a 100644 --- a/scripts/db.js +++ b/scripts/db.js @@ -10,7 +10,7 @@ const MYSQL_CONFIG = { ...(process.env.MYSQL_PORT && { port: process.env.MYSQL_PORT }), }; -const connection = mysql.createConnection(process.env.CLEARDB_DATABASE_URL ? process.env.CLEARDB_DATABASE_URL : MYSQL_CONFIG); +const connection = mysql.createConnection(process.env.DATABASE_URL ? process.env.DATABASE_URL : MYSQL_CONFIG); const query = util.promisify(connection.query.bind(connection)); const usersCreate = query('CREATE TABLE `users` (\n' +