##Application Programming Interface (API)
###Introduction
To get started with Running Argent Push Server you will need the following system configuration
Required dependencies
.bash_profile
environment variables + view hidden filesdefaults write com.apple.finder AppleShowAllFiles YES;
killall Finder /System/Library/CoreServices/Finder.app
Request the Argent local .bash_profile
file from a Argent administrator
Other environment variables should shadow production/dev env variables on Heroku
- NodeJS (v.4.2.4)
- Bower
- Gulp
- Mongo express
- MongoDB
- Homebrew
- Nodemon
- Docco
sudo npm i docco -g
sudo npm i nodemon -g
#####Do not do the following unless absolutely necessary, it give files root permissions for installs to runsudo chmod -R 0777 argent
sudo chmod -R 0777 argent-api
Use Homebrew to install Mongoruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Thenbrew install mongodb
####HOWTO: Create MongoDB instance to run API locallysudo mkdir -p data/db
sudo chmod -R 0777 data/db
sudo mongod --dbpath data/db
Check localhost:27017
to see mongo runningmongo-express -u user -p password -d database
Check localhost:8081
to see mongo database
####HOWTO: Generate Documentationdocco *.js
Run nodemon server
to instantiate API
API will now be running on http://localhost:5001
Local MongoDB will now be running on http://localhost:8081
Mongo Connection open on http://localhost:27017/{dbname}
##Angular 1.3.8 User Interface (UI)
Run the following commandssudo npm i bower -g
sudo npm i gulp -g
sudo npm i
sudo bower i
SASS!important
Fix for node-sass, lib-sass necessarynode sassdef
Compile SASS files to CSS build files
Edit the following in src/app/index.js
to match local settings
.value('appconfig',{ apiRoot: 'http://localhost:5001', firebaseUrl: 'https://demosandbox.firebaseio.com/api/v1'})
Run nodemon server
to instantiate Angular frontend
App should now be running on http://localhost:5000
Requests will be made to the local API at http://localhost:5001
##Staging and Deployment
###Firebase
#####URLsSandbox: https://demosandbox.firebaseio.com
Production: https://argent.firebaseiocom
To set up a new Firebase instance be sure to enable Email & Password User Authentication
Be sure to include the following security rules
{ "rules": { "api" :{ "v1" : { "users": { "$username" :{ "logs": { ".read": "$username === auth.username && auth.uid !== null && auth.hasTCAccess === true", ".write": "$username === auth.username && auth.uid !== null && auth.hasTCAccess === true" }, "projects": { ".read": "$username === auth.username && auth.uid !== null && auth.hasTCAccess === true", ".write": "$username === auth.username && auth.uid !== null && auth.hasTCAccess === true" }, "status": { ".read": "$username === auth.username && auth.uid !== null && auth.hasTCAccess === true", ".write": "$username === auth.username && auth.uid !== null && auth.hasTCAccess === true" }, "tasks": { ".read": "$username === auth.username && auth.uid !== null && auth.hasTCAccess === true", ".write": "$username === auth.username && auth.uid !== null && auth.hasTCAccess === true" } } } } } }}
###Heroku
Download Heroku Toolbelt
https://toolbelt.heroku.com/osx
With Two-Factor Authenticationheroku login
and enter credentials
Add any domain endpoints necessaryheroku domains:add {mydomainname}
Production Ready Checklist:
- Add MongoLab
- Add Expedited SSL
- Add SSL
- Add Librato
- Add Logentries
- Scale Dynos
Since our Heroku instance has two-factor authentication enabled you will need an app such as Google Authenticator to login
###Stripe
Be sure to have correct public key and sandbox keys
https://dashboard.stripe.com
The API Will configure the correct local development environment and production environment
The Angular frontend will require configuring client key values in src/app/index.js
###GitHub
https://help.github.com/articles/set-up-git/
In order to clone with two-factor authentication enabled you must set up an access token
https://github.com/settings/tokens > generate new token
Sign in using username and access token as password.
To commit to Github
git branch {branchname}
git add {files to commit}
**ignore adding src/app/index.js unless absolutely necessarygit commit -m 'my commit'
git push -u origin {branchname}
To ensure identities for commitsgit config user.name "{githubusername}"
git config --global user.email "{your_email@example.com}"
###BlueHost
In order to connect Heroku to a domain name server you will need to adjust the CNAME entry
- Remove currently existing www CNAME
- To do this add a new www CNAME pointing to
http://{myapp}.herokuapp.com
- This will now point the domain to the Heroku instance
Be sure to add a redirect rule (with or without www) to your app instance
- Non-Secured: Add redirect rule (with or without www) to
http://www.{myapp}.com
- Secured SSL: Add redirect rule (with or without www) to
https://www.{myapp}.com
In order to create a subdomain pointing to an API instance you will need to add a new CNAME Record
- Add CNAME Record api
- Point CNAME Record to
https://{myapi}.herokuapp.com
###SSL
To correctly provision the SSL it is recommended to use a service such as Expedited SSL
- Once the third-party SSL Service has been installed, edit your www CNAME to point to the SSL endpoint (e.g.
https://floatingbreeze8293.herokuapp.com
)
###Push NotificationsFollow this: http://stackoverflow.com/questions/21250510/generate-pem-file-used-to-setup-apple-push-notificationAnd this: https://github.com/argon/node-apn/wiki/Preparing-Certificates
Useful commandsopenssl x509 -in aps.cer -inform DER -outform PEM -out cert.pemopenssl pkcs12 -in key.p12 -out key.pem -nodes
Detailed instructionsGo to developer.apple.comFollow directions to create an aps.cer using a csr generated from macDownload the aps.cer, double click on it to bring it into keychain or drag it into keychainRename aps.cer to cert.cerClick arrow on left of the new certificate, shift select both the cert and the key row below itRight click 'Export 2 items'Generate a key .p12 file, name it 'key' and you will get a key.p12Create a directory somewhere to store the cert.cer (renamed from aps.cer) and the key.p12 file (ex: ~/src/push/cert/v1/)Execute the following commands$ openssl x509 -in cert.cer -inform DER -outform PEM -out cert.pem$ openssl pkcs12 -in key.p12 -out key.pem -nodesNow put the generated .pem files into the base root of any push notification server and you're ready to go!
###QUESTIONS?
For any questions please email support