santteegt / simple-ride

Webapp for the Simple Ride platform based on Ionic 3 and Meteor framework as backend
0 stars 0 forks source link
angular4 bootstrap cordova ionic3 meteor

SimpleRide

Webapp for the Simple Ride platform based on Ionic 3.x.x and Meteor framework >1.4 as backend

1. Prerequisites

In case you are some releases ahead Meteor required version, downgrade using the following steps:

$ sudo rm /usr/local/bin/meteor
$ rm -rf ~/.meteor
$ sudo chown -R $(whoami) ~/.npm
$ curl "https://install.meteor.com/?release=1.6.0.1" | sh

2. Deploy/Build app for production

REMEMBER to configure environment variabled under api script definition in the packages.json file.

REMEMBER to copy your iOS push certificates into api/private/push_certs

$ cd api && meteor npm install
$ npm run api # Configure api script parameters accordingly in the packages.json file

2.1 Mobile app setup

npm install
$ cd api
$ meteor [--release 1.6.0.1] remove angular2-compilers barbatus:angular2-polyfills
$ meteor [--release 1.6.0.1] add ecmascript
$ cd ..
$ npm run meteor-client:bundle # Configure meteor-client.config.json accordingly
$ ionic cordova run [android|ios] # run on a connected device
$ ionic cordova run [android|ios] --prod --release # run on a connected device for production testing

2.1.1 Common issues when trying to run the app

2.1.1.1 meteor-client-bundler is automatically updating meteor version?
vi meteor-client-bundler
line 35 to -> Execa.sync("meteor", ["create", "--release", "1.6.0.1", tempDir], {
line 79 to -> Execa.sync("meteor", ["--release", "1.6.0.1", "build", "--debug", "--directory", "."], {
2.1.1.2 uint8 problem in meteor-client
_require('core-js/modules/es6.typed.uint8-array'); // 56
_require('core-js/modules/es6.typed.uint32-array'); // 57

2.1.1.3 cordova-plugin-file-transfer problem

ionic cordova plugin add cordova-plugin-file-transfer@1.6.3 --force

2.1.2 Android setup

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }
    }
}
mv build-extras.gradle.example platforms/android/build-extras.gradle
android {
  ...
  ...
  flavordimensions "default"
  ...
  ...

2.1.3 iOS setup

NSLocationWhenInUseUsageDescription: string description

NSCameraUsageDescription: string description

NSPhotoLibraryUsageDescription: string description of the need of accessing the user photo library

NSMotionUsageDescription: string description of the need of accesing the user geolocation while he is in motion

2.2 Push Notifications Setup

  1. Enable the following code under the server/main.js file
import "./imports/push.js"; // ENABLE PUSH NOTIFICATIONS

2.2.1 iOS

  1. If you already have valid certificates, jump through to step 8
  2. Generate Push Notification Certificates for development and production through the Apple Developer site. (aps_development.cer & aps.cer)
  3. Import them into the KeyChain Access
  4. Export them into .p12 certificates (name them as CertificateDev.p12 & CertificateProd.p12 respectively)
  5. Run the following commands:
$ openssl x509 -in aps_development.cer -inform DER -outform PEM -out SimpleRide-dev.pem
$ openssl pkcs12 -in CertificateDev.p12 -out SimpleRideKey-dev.pem -nodes
$ openssl x509 -in aps.cer -inform DER -outform PEM -out SimpleRide-prod.pem
$ openssl pkcs12 -in CertificateProd.p12 -out SimpleRideKey-prod.pem -nodes
  1. Optionally, you can test the certificates by running the following:
# Development
$ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert meteorApp-cert-dev.pem -key meteorApp-key-dev.pem
# Production
$ openssl s_client -connect gateway.push.apple.com:2195 -cert meteorApp-cert-prod.pem -key meteorApp-key-prod.pem
  1. Paste the generated files on the private/push_certs folder
  2. If you are testing push notifications under development, enable the following lines on the server/main.js file:
// For testing push notifications under development
declare var process;
process.env.NODE_ENV = "development";
  1. Configure the server/imports/push.js file accordingly

  2. Remember to enable Push Notifications on XCode before Archiving the app to be uploaded to the App Store, or for local development

2.2.2 Android

  1. You need to obtain a Server API Key and a SENDERID from the Firebase Cloud Messaging console

  2. Update the SENDERID value on the src/app/pages/login/login.component.mobile.ts component

  3. Update the FCM API key on the file server/imports/push.js

  4. If you are testing push notifications under development, enable the following lines on the server/main.js file:

// For testing push notifications under development
declare var process;
process.env.NODE_ENV = "development";
  1. In production, remember to link your FCM APi Key with the app in Google Play. Take a look at this README for instructions

2.3 Deploying the Server under a AWS EC2 instance using mup

2.3.1 Backend Setup

2.3.2 Configuring mup

cd api/.deploy
mup setup
mup deploy

More info about conf: click here

cd api/.deploy
mup logs -f

2.4 MongoDB Backup

3. Local Deployment

3.1 Run the mobile app locally

To run the app locally, you need an NGINX instance with the following configuration:

server {
    listen      80;
    server_name <API-SERVER-IP-ADDRESS>;

    location / {
      proxy_pass http://<MOBILEAPP-CLIENT-IP-ADDRESS>:8100;
    }
    location ~ ^/(_oauth|packages|ufs) {
      proxy_pass http://<API-SERVER-IP-ADDRESS>:3000;
    }
    location /sockjs {
      proxy_pass http://<API-SERVER-IP-ADDRESS>:3000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }

    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
    }
}

For a complete config file example, take a look to the nginx.conf.example file.

To restart nginx service you can use the following commands:

$ kill -QUIT $( cat /run/nginx.pid )
$ /usr/sbin/nginx -t -c /etc/nginx/nginx.conf # IF YOU WANT TO TEST THE CONFIG FILE FIRST
$ /usr/sbin/nginx -c /etc/nginx/nginx.conf # START THE SERVICE. In UBUNTU, you can use systemctl [stop|start] nginx.service

Finally, to start serving the mobile app in your local machine, run the following command:

ionic serve # run on the desktop

3.2 Develop/Test admin pages locally

4. Deploy/Build development environment using Heroku

A development environment is available in this instance on Heroku

If deploying to Heroku for the first time, follow the instructions in this link. On the other hand, if you want to deploy the app into an existing Heroku instance, run heroku git:clone -a simpleride and add the origin remote to sync the repo.

In case your Heroku instance is not already configured, remember to configure the following environment variables in order to successfully deploy the app

heroku config:add APN_CERT="$(cat $PATH_TO_SimpleRide-dev.pem)"
heroku config:add APN_CERT="$(cat $PATH_TO_SimpleRideKey-dev.pem)"
heroku config:add BUILDPACK_PRELAUNCH_METEOR=1
heroku config:add METEOR_APP_DIR=api/
heroku config:add METEOR_SETTINGS="$(cat $PATH_TO_settings.json)"
heroku config:add MONGODB_URI=$URL_TO_mLab_INSTANCE
heroku config:add ROOT_URL=https://simpleride.herokuapp.com # in case you're using existing Heroku instance 'simpleride'