##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 files
defaults 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 run
sudo chmod -R 0777 argent
sudo chmod -R 0777 argent-api
Use Homebrew to install Mongo
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then
brew install mongodb
####HOWTO: Create MongoDB instance to run API locally
sudo mkdir -p data/db
sudo chmod -R 0777 data/db
sudo mongod --dbpath data/db
Check localhost:27017
to see mongo running
mongo-express -u user -p password -d database
Check localhost:8081
to see mongo database
####HOWTO: Generate Documentation
docco *.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 commands
sudo npm i bower -g
sudo npm i gulp -g
sudo npm i
sudo bower i
SASS
!important
Fix for node-sass, lib-sass necessary
node 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
#####URLs
Sandbox: 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 Authentication
heroku login
and enter credentials
Add any domain endpoints necessary
heroku 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 necessary
git commit -m 'my commit'
git push -u origin {branchname}
To ensure identities for commits
git config user.name "{githubusername}"
git config --global user.email "{[email protected]}"
###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 Notifications Follow this: http://stackoverflow.com/questions/21250510/generate-pem-file-used-to-setup-apple-push-notification And this: https://github.com/argon/node-apn/wiki/Preparing-Certificates
Useful commands openssl x509 -in aps.cer -inform DER -outform PEM -out cert.pem openssl pkcs12 -in key.p12 -out key.pem -nodes
Detailed instructions Go to developer.apple.com Follow directions to create an aps.cer using a csr generated from mac Download the aps.cer, double click on it to bring it into keychain or drag it into keychain Rename aps.cer to cert.cer Click arrow on left of the new certificate, shift select both the cert and the key row below it Right click 'Export 2 items' Generate a key .p12 file, name it 'key' and you will get a key.p12 Create 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 -nodes Now 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