Legit-o-Meter is an interactive digital learning tool for students and teachers to evaluate the legitimacy of online news. This app is part of the Fake the News Project funded by Mozilla Hive ATX.
A staged version of the site is hosted at: legitornot-test.herokuapp.com
Current Status: Our team is actively developing a working prototype led by @rallyjinx, @mateoclarke, and @seandellis.
TODO
This project was bootstrapped with Create React App. It uses Node.js and Express.js with Knex providing a query building for a Postgres datastore. The project uses Semantic UI framework for styling UI components.
To get setup:
-
Download Node
npm install
-
Download Postgres
- We used the Postgres Mac app. Once you open it for the first time, initialize it.
- You will probably need to add this to your bash or zsh config
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
-
Create a database
- Install knex.js
npm install knex -g
- Create the database
createdb legit-o-meterdb
- Migrate and Seed the database
knex migrate:latest
knex seed:run
-
Run both the front-end React client app and the back-end Node server
- Node/Express Back-end Server
npm start
- React Front-End Client App
cd react-ui
npm start
- Publish
master
branch.
git push heroku master
- Run db migration on heroku (if necessary)
heroku run knex migrate:migrate --knexfile server/knexfile.js
- It might be necessary to Reset the database in the Heroku console. BUT this looses all the data
heroku run knex migrate:rollback --knexfile server/knexfile.js
A minimal example of using a Node backend (server for API, proxy, & routing) with a React frontend.
To deploy a frontend-only React app, use the static-site optimized
A combo of two npm projects, the backend server and the frontend UI. So there are two package.json
configs.
package.json
for Node server & Heroku deployheroku-postbuild
script compiles the webpack bundle during deploycacheDirectories
includesreact-ui/node_modules/
to optimize build time
react-ui/package.json
for React web UI- generated by create-react-app
Demo deployment: example API call from the React UI is fetched with a relative URL that is served by an Express handler in the Node server.
git clone https://github.com/mars/heroku-cra-node.git
cd heroku-cra-node/
heroku create
git push heroku master
This deployment will automatically:
- detect Node buildpack
- build the app with
npm install
for the Node serverheroku-postbuild
for create-react-app
- launch the web process with
npm start
- serves
../react-ui/build/
as static files - customize by adding API, proxy, or route handlers/redirectors
- serves
package-lock.json
? We resolved a compatibility issue. See PR for more details.
👓 More about deploying to Heroku.
If an app was previously deployed with create-react-app-buildpack, then a few steps are required to migrate the app to this architecture:
-
Remove create-react-app-buildpack from the app; heroku/nodejs buildpack will be automatically activated
heroku buildpacks:clear
-
Move the root React app files (including dotfiles) into a
react-ui/
subdirectorymkdir react-ui git mv [!react-ui]* react-ui/ # You'll see "fatal: Not a git repository"; let's fix that error mv react-ui/.git ./
-
Create a root
package.json
,server/
, &.gitignore
modeled after the code in this repo -
Commit and deploy ♻️
git add -A git commit -m 'Migrate from create-react-app-buildpack to Node server' git push heroku master
In a terminal:
# Initial setup
npm install
# Start the server
npm start
The React app is configured to proxy backend requests to the local Node server. (See "proxy"
config)
In a separate terminal from the API server, start the UI:
# Always change directory, first
cd react-ui/
# Initial setup
npm install
# Start the server
npm start