CommUnity XP is an online platform for students to connect with each other and find resources about mental health. Our vision is to bridge the gap between students facing mental health issues and the resources available to them, and hopefully reduce the stigma surrounding mental illness.
- Instagram: @community_xp
- Email: Contact Mack at mack@communityxp.ca
- Live site coming soon!
First cd client && npm install
.
In the project directory, you can run:
-
npm start
: Runs the app in the development mode at http://localhost:3000. The linter will run, and there is hot-reload enabled. -
npm run build
: Builds an optimized/minified bundle of React and the app, located in the thebuild
folder. Ready for deployment!
API_HOST
: defaults tolocalhost:8000
where the server should be running if you are planning to test client-server functionsAPI_KEY
: default is unset. only necessary if you are working with the live dev server. ignore for local development.
In src
there are five folders and the index.js
file. The folders are as follows:
assets
: For documents, images, and other static content to render.css
: All the CSS files go here!pages
: Despite React being a single page app, this is where large wrapper components that can be thought of as colloquial "pages" are located. For instance, the Home/Landing page. These components are usually used in only one location, which also qualifies them as pages (vs comps).comps
: Smaller React components that belong to each of the pages and that will be used in multiple places.test
: Test files and fixtures go here. Empty and useless at the moment.
- React: React v16.13.1, React-scripts v3.4.1, React-Router v5.2.0, React-Bootstrap v1.0.1. Bootstrapped with Create React App.
- Node: 8.17
- NPM: 6
cd server && npm install
Runs on Node JS 12 with Express.
npm start
: Simply runsnode app.js
(no hot reload for now)npm run deploy
: Runs the deploy script
The following environment variables are passed to the server on startup:
RESOURCE_DB_HOST
: defaults to localhostRESOURCE_DB_USER
: defaults topostgres
RESOURCE_DB_PWD
: defaults to null, required if the DB has a passwordRESOURCE_DB_PORT
: defaults to 5432, not requiredRESOURCE_DB_NAME
: defaults toresources
In order to set these so process.env
can find them, you can use fancy env plugins like dotenv, or you can just run the following to export them to your RC file:
echo 'export <VAR_NAME>=<val>' >> ~/.<rc_file>
Using local Postgres DB:
- Install postgres and start local server
- Using a postgres client, create a
resources
db and table. Use the/db/create_schema.sql
file to help you. - Set the above environment variables if the defaults are not correct
- Start the server with
npm start
Using the live dev DB:
- Get the required DB credentials from Mack. Do not share these creds or commit them to code.
- Set the creds to the environment variables above
- Start the server with
npm start
This express server is deployed (currently only to development stage) using AWS Lambda, AWS API-Gateway, and the Serverless Framework.
How to deploy:
- Make your local changes to
app.local.js
and test that that works. DO NOT edit the last 6 lines of this file, after the comment about this. DO NOT make changes toapp.js
, as they will be overridden by deploy. - When ready to deploy, make sure you have globally installed the serverless framework:
npm -g install serverless
. Confirm by runningsls -v
. - Run the deploy script with
npm run deploy
from the/server
directory. That's it - serverless takes care of the rest. - The serverless deploy will print out an endpoint to your terminal. Use this to test - this is the live server!
Making Changes
/scripts/deploy.sh
is the Bash file that prepares the file to deploy, and executes the serverless commandserverless.yml
in the top level handles the configuration of the serverless deployment to AWS Lambda- AWS Console will have tools to make other changes such as permissions, API keys, roles, logs, etc.
- GET
/ping
: for healthcheck, should return 200 - GET
/v1/resource/all
: fetch JSON array of all the resources - GET
/v1/resource/id/:id
: fetch resource JSON by integerid
- GET
/v1/resource/name/:name
: fetch resource JSON by stringname
No insert or update, can do those manually with psql queries for now.
Requires API Key provided by the UXP team.