This is the backend server for the "The Codes" web app.
Live version of server: https://warm-harbor-99058.herokuapp.com/
Client repo: https://github.com/MatthewMacomber/TheCodes-client
- Install dependencies:
npm install
- Create development and test databases:
createdb thecodes
,createdb thecodes-test
- Create database user:
createuser thecodes
- Grant privileges to new user in
psql
:GRANT ALL PRIVILEGES ON DATABASE thecodes TO thecodes
GRANT ALL PRIVILEGES ON DATABASE "thecodes-test" TO thecodes
- Prepare environment file:
cp example.env .env
- Replace values in
.env
with your custom values. - Bootstrap development database:
npm run migrate
- Bootstrap test database:
npm run migrate:test
For tests involving time to run properly, your Postgres database must be configured to run in the UTC timezone.
- Locate the
postgresql.conf
file for your Postgres installation.- OS X, Homebrew:
/usr/local/var/postgres/postgresql.conf
- OS X, Homebrew:
- Uncomment the
timezone
line and set it toUTC
as follows:
# - Locale and Formatting -
datestyle = 'iso, mdy'
#intervalstyle = 'postgres'
timezone = 'UTC'
#timezone_abbreviations = 'Default' # Select the set of available time zone
- To seed the database for development:
psql -U thecodes -d thecodes -a -f seeds/seed.thecodes_tables.sql
- To clear seed data:
psql -U thecodes -d thecodes -a -f seeds/trunc.thecodes_tables.sql
- Start application for development:
npm run dev
- Run tests:
npm test
When your new project is ready for deployment, add a new Heroku application with heroku create
. This will make a new git remote called "heroku" and you can then npm run deploy
which will push to this remote's master branch.
/api/codes
- GET
/
Returns list of all codes. Returns array of objects. - GET
/usercodes
Requires auth. Returns list of authed user codes. Returns array of objects. - POST
/usercodes
Requires auth. Create a new code under authed user. Returns code object. - GET
/:code_id
Requires auth. Returns requested code. Returns code Object.
- GET
/api/answers
- GET
/
Requires auth. Returns list of authed user answers. Returns array of objects. - POST
/
Requres auth. Create a new answer under authed user. Returns answer object. - GET
/list
Requires admin auth. Returns list of all answers. Returns array of objects. - GET
/:answer_id
Requires auth. Returns request answer for authed user. Returns answer object.
- GET
/api/auth
- POST
/login
Verifies passed login credentials. Returns JWT object if successful login.
- POST
/api/users
- POST
/
Regisister new user after verifying passed user data. Returns new user id and user data if succesful. - GET
/:user_id
Returns username of requested user_id. Returns string.
- POST
/api/requests
- GET
/
Requires admin auth. Returns list of all requests. Return array of objects. - POST
/
Requires auth. Creates a new request. Returns request object. - GET
/:request_id
Requires admin auth. Return requested request. Returns request object. - DELETE
/:request_id
Requires admin auth. Deletes specified request. Returns status 204.
- GET
/api/admin
- POST
/
Admin specific login. Returns JWT object if successful login. - GET
/users
Requires admin auth. Returns list of all users. Returns array of objects. - GET
/user/:user_id
Requires admin auth. Return requested user. Returns user object.
- POST
/
- GET
/
Returns 'The Codes Server.'
- GET
- Node.js
- bcryptjs
- cors
- dotenv
- express
- helmet
- jsonwebtoken
- knex
- morgan
- pg
- postgrator-cli
- treeize
- uuid
- xss
- PostgreSQL