#55 Add config based on environment vars
Merged 7 months ago by a2batic. Opened 7 months ago by amitosh.
amitosh/Fedora-app app-env  into  master

file modified
+3 -0

@@ -33,3 +33,6 @@ 

  .DS_Store

  Thumbs.db

  UserInterfaceState.xcuserstate

+ 

+ # Config

+ src/app/config.*.ts

file modified
+5 -3

@@ -1,8 +1,8 @@ 

- # ![Fedora-Logo](https://pagure.io/fork/thelittlewonder/Fedora-app/raw/master/f/Screenshots/FedoraLogo.png) Fedora App

+ # ![Fedora-Logo](https://pagure.io/Fedora-app/raw/master/f/Screenshots/FedoraLogo.png) Fedora App

  

- ![Screenshot](https://pagure.io/fork/thelittlewonder/Fedora-app/raw/master/f/Screenshots/HomeScreen.png)

+ ![Screenshot](https://pagure.io/Fedora-app/raw/master/f/Screenshots/HomeScreen.png)

  

- [![Get it on Google Play](https://pagure.io/fork/thelittlewonder/Fedora-app/raw/master/f/Screenshots/GetItOnGooglePlay.png)](https://play.google.com/store/apps/details?id=com.fedoraqa.fedora)

+ [![Get it on Google Play](https://pagure.io/Fedora-app/raw/master/f/Screenshots/GetItOnGooglePlay.png)](https://play.google.com/store/apps/details?id=com.fedoraqa.fedora)

  

  The Fedora Project is a global partnership of free software community members. The Fedora Project is sponsored by Red Hat, which invests in our infrastructure and resources to encourage collaboration and incubate innovative new technologies. Some of these technologies may later be integrated into Red Hat products. They are developed in Fedora and produced under a free and open source license from inception, so other free software communities and projects are free to study, adopt, and modify them.

  

@@ -13,6 +13,7 @@ 

  [Fedora App on Google Play Store](https://play.google.com/store/apps/details?id=com.fedoraqa.fedora)

  

  ## Technologies Used

+ 

  Angular, Ionic 3, TypeScript, SCSS

  

  ## Current features

@@ -62,6 +63,7 @@ 

  

  * Clone this repository: `git clone https://pagure.io/Fedora-app.git`.

  * Run `npm install` from the project root.

+ * Copy `src/app/config.env.ts.example` to `src/app/config.dev.ts` and `src/app/config.prod.ts`. Replace the example API keys inside them with real API keys.

  * Run `ionic serve` in a terminal from the project root.

  * Open http://localhost:8100 to preview your app.

  * Profit. :tada:

file modified
+15 -1

@@ -188,6 +188,21 @@ 

        "resolved": "https://registry.npmjs.org/@types/localforage/-/localforage-0.0.30.tgz",

        "integrity": "sha1-PWCmv23aOOP4pGlhFZg3nx9klQk="

      },

+     "@types/lodash": {

+       "version": "4.14.108",

+       "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.108.tgz",

+       "integrity": "sha512-WD2vUOKfBBVHxWUV9iMR9RMfpuf8HquxWeAq2yqGVL7Nc4JW2+sQama0pREMqzNI3Tutj0PyxYUJwuoxxvX+xA==",

+       "dev": true

+     },

+     "@types/lodash-es": {

+       "version": "4.17.0",

+       "resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.0.tgz",

+       "integrity": "sha512-h8lkWQSgT4qjs9PcIhcL2nWubZeXRVzjZxYlRFmcX9BW1PIk5qRc0djtRWZqtM+GDDFhwBt0ztRu72D/YxIcEw==",

+       "dev": true,

+       "requires": {

+         "@types/lodash": "4.14.108"

+       }

+     },

      "abbrev": {

        "version": "1.1.1",

        "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",

@@ -3074,7 +3089,6 @@ 

          "os-tmpdir": {

            "version": "1.0.2",

            "bundled": true,

-           "dev": true,

            "optional": true

          },

          "osenv": {

file modified
+5 -1

@@ -4,6 +4,9 @@ 

    "description": "Fedora mobile app",

    "main": "index.js",

    "private": true,

+   "config": {

+     "ionic_webpack": "./webpack.config.js"

+   },

    "scripts": {

      "clean": "ionic-app-scripts clean",

      "build": "ionic-app-scripts build",

@@ -66,6 +69,7 @@ 

    },

    "devDependencies": {

      "@ionic/app-scripts": "3.1.8",

+     "@types/lodash-es": "^4.17.0",

      "typescript": "2.4.2"

    },

    "cordova": {

@@ -88,4 +92,4 @@ 

        "android"

      ]

    }

- } 

\ No newline at end of file

+ }

@@ -0,0 +1,21 @@ 

+ // Copy this file into config.dev.ts and config.prod.ts

+ // for dev settings and prod settings respectively

+ 

+ const FB_CONFIG = {

+   accessToken: '123456789012345|8exAMp1e3iDWxl92d6pgj0xC3a8',

+   xfbml: true,

+   version: 'v2.6'

+ };

+ 

+ const TWITTER_CONFIG = {

+   BEARER_TOKEN: 'AAAAAEXAMPLEAAAAAAAAMmWwEXAMPLE9tGRvIFnIR8XYXmIFTFaEGagjX0%3Dup2JDIi9hjbCJKGaEGDqkLMtYSGumkyMa6SbwXx0FMB1vOlvN0';

+ };

+ 

+ const ENV = {

+   // change this to true, in config.prod.ts

+   PROD: false,

+   FB_CONFIG,

+   TWITTER_CONFIG

+ };

+ 

+ export default ENV;

file modified
+6 -1

@@ -1,5 +1,10 @@ 

  import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

- 

+ import ENV from '@environment';

  import { AppModule } from './app.module';

+ import { enableProdMode } from '@angular/core';

+ 

+ if (ENV.PROD) {

+   enableProdMode();

+ }

  

  platformBrowserDynamic().bootstrapModule(AppModule);

file modified
+2 -2

@@ -46,14 +46,14 @@ 

        .then((posts:Array<any>) => {

          this.posts = posts;

          this.mergeUpdates();

-       }).catch((err) => console.log(err + "kanika"));

+       });

  

      this.tw

        .getTimelineTweets(this.USER.TW)

        .then((tweets:Array<any>) => {

          this.tweets = tweets;

          this.mergeUpdates();

-       }).catch((err) => console.log(err));

+       });

    }

  

    mergeUpdates() {

file modified
+2 -6

@@ -1,14 +1,10 @@ 

  import { Injectable } from '@angular/core';

  import 'rxjs/add/operator/map';

+ import ENV from '@environment';

  

  import { Facebook } from 'fb';

  import * as _ from 'lodash';

  

- const FB_CONFIG = {

-   accessToken: '1242536905766029|8btZ0cyO3iDWxl92d6pgj0xC3a8',

-   xfbml: true,

-   version: 'v2.6'

- };

  

  /*

    Generated class for the Fb provider.

@@ -20,7 +16,7 @@ 

  export class FB {

    private fb:Facebook;

    constructor() {

-     this.fb = new Facebook(FB_CONFIG);

+     this.fb = new Facebook(ENV.FB_CONFIG);

    }

  

    api(urlParts) {

@@ -29,12 +29,12 @@ 

      this.isCordova = window.hasOwnProperty('cordova');

      this.isLiveReload = false;

  

-     this.http

-       .get('http://localhost:8100')

-       .subscribe(

-         res => this.isLiveReload = !_.isEmpty(res),

-         err => console.log(this.useProxy())

-       );

+     // this.http

+     //   .get('http://localhost:8100')

+     //   .subscribe(

+     //     res => this.isLiveReload = !_.isEmpty(res),

+     //     err => console.log(this.useProxy())

+     //   );

    }

  

    private startHandler = () => {

@@ -42,7 +42,6 @@ 

    }

  

    private stopHandler = () => {

-     console.log(this);

      this.spinnerDialog.hide();

    }

  

file modified
+2 -4

@@ -1,8 +1,8 @@ 

  import { Injectable } from '@angular/core';

  import 'rxjs/add/operator/map';

+ import ENV from '@environment';

  

  import * as _ from 'lodash';

- 

  import { Request } from '../request/request';

  

  

@@ -14,8 +14,6 @@ 

  }

  API.timeline = API.statuses.concat(['user_timeline.json']);

  

- const BEARER_TOKEN = 'AAAAAAAAAAAAAAAAAAAAAMmWwAAAAAAA9tGRvIFnIR8XYXmIFTFaEGagjX0%3Dup2JDIi9hjbCJKGaEGDqkLMtYSGumkyMa6SbwXx0FMB1vOlvN0';

- 

  /*

    Generated class for the Tw provider.

  

@@ -31,7 +29,7 @@ 

      return new Promise((resolve, reject) => {

        this.request.get(

          API.timeline, { screen_name: user },

-         { 'Authorization': 'Bearer ' + BEARER_TOKEN }

+         { 'Authorization': 'Bearer ' + ENV.TWITTER_CONFIG.BEARER_TOKEN }

        ).then(data => {

            var tweets = _.map(data, t => {

              return {

file modified
+5 -0

@@ -1,5 +1,10 @@ 

  {

    "compilerOptions": {

+     //...

+     "baseUrl":  "./src",

+     "paths": {

+       "@environment": ["app/config.prod"]

+     },

      "allowSyntheticDefaultImports": true,

      "declaration": false,

      "emitDecoratorMetadata": true,

file added
+9

@@ -0,0 +1,9 @@ 

+ const path = require('path');

+ const useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');

+ 

+ module.exports = function () {

+     useDefaultConfig[process.env.IONIC_ENV].resolve.alias = {

+         "@environment": path.resolve(__dirname + '/src/app/config.' + process.env.IONIC_ENV + '.ts'),

+     };

+     return useDefaultConfig;

+ };

Introduces two files src/app/config.dev.ts and src/app/config.prod.ts to store configuration such as keys that should be local to the development environment.

Closes #52

I think it will be best to revoke the existing tokens and insert a new set of tokens into the config files.

rebased onto e93264c

7 months ago

Pull-Request has been merged by a2batic

7 months ago