Thanks for checking out our code. The documentation below may be incomplete or incorrect. We welcome pull requests! But we're a very small team, so we can't guarantee timely responses.
You need to install redis locally, then follow the steps to launch it on startup (on the default port of 6379). For OSX/MacOS:
brew install redisArch Linux:
pacman -S redis
systemctl enable redis.service
systemctl start redis.serviceUbuntu Linux:
sudo apt-get -y install redis-server
sudo systemctl enable redis
sudo systemctl start redisCreate a .env file in the root directory by copying .env.example. More info about specific keys below:
ADMIN_GOOGLE_CLIENT_*: To access the admin console. Get these values from the hylo-admin Google project.DEBUG_SQL: set totrueif you want to output the SQL used within knex/bookshelfDATABASE_URL: set to your local DB instanceEMAIL_SENDER: set to your email addressMAPBOX_TOKEN: get a token from Mapbox or email dev@hylo.com for oneOIDC_KEYS: set to a base64 string of a RSA key, you can generate one withopenssl genrsa 2048 | base64ROLLBAR_SERVER_TOKEN: use thepost_server_itemtoken in RollbarSENDWITHUS_KEY: set up a test key in SendWithUs to send all email only to you (ask someone with admin rights to set this up)SLACK_APP_CLIENT_ID: set up an app on Slack and reference its' client id, optional for dev installationSLACK_APP_CLIENT_SECRET: reference the client secret from that same app on Slack, optional for dev installation
Make sure you have Postgres running with PostGIS installed and your user has create database privileges. Then you should be able to use one of the following scenarios.
createdb hylo -h localhost
createdb hylo_test -h localhost
cat migrations/schema.sql | psql hylo
yarn knex seed:runNote: This will trash everything in your current hylo database, so make sure you really want to do that! You can run yarn knex seed:run anytime you want to refresh the database but this will delete groups, users, and posts.
createdb hylo -h localhost
createdb hylo_test -h localhost
cat migrations/schema.sql | psql hylo
NODE_ENV=dummy yarn knex seed:runThe script will ask for confirmation. By default the test user will be test@hylo.com with password hylo, configurable at the top of seeds/dummy/dummy.js.
Note: This will trash everything in your current hylo database, so make sure you really want to do that! You can run NODE_ENV=dummy yarn knex seed:run anytime you want to refresh the database but this will delete groups, users, and posts.
If you are working with farm group data, run this command to add fake farm data to either a database copy, or a db copy generated by the seeding function. This function is not designed to be run more than once successfully.
createdb hylo -h localhost
createdb hylo_test -h localhost
cat migrations/schema.sql | psql hylo
NODE_ENV=farmdev yarn knex seed:runNote: You will not be able to run NODE_ENV=farmdev yarn knex seed:run more than once. Alternatively, drop the production DBs and re-run the script.
Scroll down to "loading database snapshots" 👇
yarn devThis reads the .env file you created above, using dotenv, and starts two processes managed by foreman: one web server process and one background job worker process, as listed in Procfile.dev. If you want to run only one of the processes, pass its name in Procfile.dev as an argument, e.g. yarn dev -- web.
Now visit localhost:3001.
Create a local certificate and make sure your computer trusts it. Here are some up to date instructions for macOS: https://deliciousbrains.com/ssl-certificate-authority-for-local-https-development/
Create a directory config/ssl and copy the .crt, key and .pem (CA certificate) files to it. Assuming the names are localhost.crt, localhost.key and localhost.pem then add a file at config/local.js with the contents:
var fs = require('fs')
var path = require('path')
module.exports = {
/**** Setup an SSL certificate for local development with SSL (so we can test iFrame embedding) ***/
ssl: process.env.PROTOCOL === 'https' ? {
ca: fs.readFileSync(path.resolve(__dirname, './ssl/localhost.pem')),
key: fs.readFileSync(path.resolve(__dirname, './ssl/localhost.key')),
cert: fs.readFileSync(path.resolve(__dirname, './ssl/localhost.crt'))
} : false
}
Change your .env file to have:
PROTOCOL=https
- Run
yarn generate-rsa-key-base64 - Copy generated base64 string to .env file:
OIDC_KEYS=base64key - You can add multiple keys by separating them with a comma (to rotate keys in the future)
Run yarn test or yarn cover. The tests should use a different database (see below), because it creates and drops the database schema on each run.
Create a file called .env.test to set environment variables for the test environment.
# NOTE: don't put comments after a variable initialization. it will break your tests!
# run tests against a different database
DATABASE_URL=postgres://localhost/hylo_test
DOMAIN=testdomain
# this prevents jobs that were queued during testing from being run in development
KUE_NAMESPACE=qtest
PROTOCOL=http
# don't log errors to Rollbar
ROLLBAR_SERVER_TOKEN=
# you can set up a SendWithUs API key to return valid responses but send no email
SENDWITHUS_KEY=test_...
INBOUND_EMAIL_SALT=FFFFAAAA123456789
INBOUND_EMAIL_DOMAIN=inbound-staging.hylo.com
PLAY_APP_SECRET=quxgrault12345678
AWS_ACCESS_KEY_ID=foo
UPLOADER_PATH_PREFIX=foo
(Without the above values, you'll see a failing test in the suite.) Since the test database was created above, npm test should work at this point.
Migrations are managed by the knex library. Create a new migration with this command:
knex migrate:make my_migration_name(You can either install knex globally with npm install -g knex, or run the version in your node_modules with ./node_modules/.bin/knex.)
Run migrations with yarn migrate and rollback the last one with yarn rollback.
The values of DB_USERNAME, DB_HOST, DB_PORT, and DB_NAME below can be obtained from DATABASE_URL in heroku config.
LOCAL_DB_NAME=hylo
DUMP_FILENAME=dbdump
pg_dump -O -U $DB_USERNAME -h $DB_HOST -p $DB_PORT $DB_NAME > $DUMP_FILENAME
# stop all processes that have open database connections, then:
dropdb $LOCAL_DB_NAME -h localhost
createdb $LOCAL_DB_NAME -h localhost
cat $DUMP_FILENAME | psql -h localhost $LOCAL_DB_NAME- GET methods on
FooControllershould return instances ofFoo. (See policies.js for some related FIXME's)
We're gradually migrating to Javascript Standard Style. The standard-formatter Atom package helps out a lot. The linter-js-standard package is also very helpful.
Our main API uses GraphQL. You can browse the queries and mutations by going to http://localhost:3001/noo/graphql and using the Documentation Explorer in the right sidebar.
Example Queries:
type Query {
me: Me
person(id: ID): Person
...
}
where Me is the currently logged-in user. For example, to load all current user's posts:
{
me {
posts {
id,
title,
type,
details,
creator {
id,
name,
avatarUrl
}
followers {
id,
name,
avatarUrl
}
followersTotal,
groups {
id,
name
},
groupsTotal,
comments {
id,
createdAt,
text,
creator {
id
}
},
commentsTotal,
createdAt,
fulfilledAt
}
}
}