Skip to content

Commit

Permalink
simplify env vars + sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
furknyavuz committed Nov 16, 2022
1 parent 45453ed commit 547f7be
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 339 deletions.
14 changes: 1 addition & 13 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,8 @@ app.disable( "x-powered-by" );
// directory that we will serve
app.use( express.static( __dirname + "/dist/company-profile-ui-template" ) );

// Not required for Cloudflare Flexible SSL configuration
// If not using Cloudflare Flexible SSL configuration redirect all requests to https
// https://support.cloudflare.com/hc/en-us/articles/115000219871-Troubleshooting-redirect-loop-errors-
/*
app.get( "*", function ( req, res, next ) {
if ( "https" !== req.headers[ "x-forwarded-proto" ] && "production" === process.env.NODE_ENV ) {
res.redirect( "https://" + req.hostname + req.url );
} else {
// Continue to other routes if we're not redirecting
next();
}
} );
*/

// redirect all requests to index.html
app.get( "/*", function ( req, res ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,24 @@ export class AboutUsPageComponent {
name: environmentCommon.website[ website ].name,
handle: environmentCommon.company.social[ website ],
cssClass: environmentCommon.website[ website ].cssClass,
url: environmentCommon.website[ website ].companyUrl
? environmentCommon.website[ website ].companyUrl
: ( environmentCommon.website[ website ].channelUrl
? environmentCommon.website[ website ].channelUrl
: environmentCommon.website[ website ].url ),
url: this.getUrl( website ),
} );
}
}
}

private getUrl( website: string ) {
let url = environmentCommon.website[ website ].url;

if ( environmentCommon.website[ website ].companyUrl ) {
url = environmentCommon.website[ website ].companyUrl;
} else if ( environmentCommon.website[ website ].channelUrl ) {
url = environmentCommon.website[ website ].channelUrl;
}

return url;
}

redirect( href: string ) {
window.location.href = href;
}
Expand Down
11 changes: 4 additions & 7 deletions src/app/service/provider/npm-provider.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from '@angular/core';
import { environment } from '../../../environments/environment';
import { environmentCommon } from '../../../environments/environment-common';
import { BRAND } from '../../data/brand/brand.data';
import { LIBRARIES, PRODUCT_LINES } from '../../data/product/product.data';
Expand All @@ -13,12 +12,12 @@ export class NpmProviderService {
PRODUCT_LINES = PRODUCT_LINES;
LIBRARIES = LIBRARIES;

constructor( private util: UtilService ) {
constructor( private utilService: UtilService ) {
// Intentionally blank
}

getNpmPackagesDownloadCount = async () => {
const today = this.util.formatDate( new Date() );
const today = this.utilService.formatDate( new Date() );
let count = 0;
for ( const system of [ PRODUCT_LINES, LIBRARIES ] ) {
for ( const productLine of system ) {
Expand All @@ -27,12 +26,10 @@ export class NpmProviderService {
const uri = `${ environmentCommon.website.npm.api.download }/${ BRAND.establishDate }:${ today }/${ environmentCommon.company.social.npm }/${ product.key }`;

// Using Xml Http Request because http.get cause CORS issue
const response = await this.util.corsRequest( uri );
const response = await this.utilService.corsRequest( uri );
if ( response != null ) {
const json = JSON.parse( response as string );
if ( environment.identity !== 'production' ) {
console.log( uri + ': ' + json.downloads );
}
this.utilService.log( uri + ': ' + json.downloads );
count += json.downloads;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/service/util/util.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import { environment } from '../../../environments/environment';

@Injectable( {
providedIn: 'root',
Expand Down Expand Up @@ -53,4 +54,10 @@ export class UtilService {
xmlHttpRequest.send();
} );
};

log( log: string ) {
if ( environment.identity !== 'production' ) {
console.log( log );
}
}
}
88 changes: 88 additions & 0 deletions src/environments/environment-init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
export const defaultEnvironmentConfigurations = {
oauth: {
twitter: {
tag: ''
},
google: {
tag: ''
},
facebook: {
tag: ''
},
linkedin: {
tag: ''
},
twitch: {
tag: ''
},
github: {
tag: ''
},
dribbble: {
tag: ''
},
reddit: {
tag: ''
}
},

payment: {
stripe: {
tag: '',
publishableKey: '',
},
coinbase: {
tag: ''
},
paypal: {
tag: '',
clientId: '',
env: ''
}
},

fileStorage: {
aws: {
tag: ''
},
googleCloud: {
tag: ''
}
},

mail: {
gmail: {
tag: ''
},
yahoo: {
tag: ''
},
outlook: {
tag: ''
}
},

sms: {
twillio: {
tag: ''
},
awsSns: {
tag: ''
}
},

analytics: {
googleAnalytics: {
tag: '',
id: ''
},
matomo: {
tag: '',
id: ''
},
mixPanel: {
tag: '',
id: ''
}
}
};
89 changes: 7 additions & 82 deletions src/environments/environment.local-to-staging-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EnvironmentModel } from '../app/model/environment/environment.model';
import { defaultEnvironmentConfigurations } from './environment-init';

export const environment: EnvironmentModel = {
identity: 'local',
Expand All @@ -9,91 +10,15 @@ export const environment: EnvironmentModel = {

clientUrl: 'http://localhost:4200',

oauth: {
twitter: {
tag: 'TWITTER_LOCAL'
},
google: {
tag: 'GOOGLE_LOCAL'
},
facebook: {
// Facebook does not allow testing social login at localhost.
tag: ''
},
linkedin: {
tag: 'LINKEDIN_LOCAL'
},
twitch: {
tag: 'TWITCH_LOCAL'
},
github: {
tag: 'GITHUB_LOCAL'
},
dribbble: {
tag: 'DRIBBBLE_LOCAL'
},
reddit: {
tag: 'REDDIT_LOCAL'
}
},
oauth: defaultEnvironmentConfigurations.oauth,

payment: {
stripe: {
tag: 'STRIPE_LOCAL',
publishableKey: 'pk_test_51I4pFdJslj2vUcp7AkRtYwCPiZJbSvGK7lNFggSbLp9LQopdnUJU44mBKlREonmvszmASnyv4FMxQztzFedllxJO00wg7mHS85',
},
coinbase: {
tag: 'COINBASE_LOCAL'
},
paypal: {
tag: 'PAYPAL_LOCAL',
clientId: 'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R',
env: 'sandbox'
}
},
payment: defaultEnvironmentConfigurations.payment,

fileStorage: {
aws: {
tag: 'AWS_LOCAL'
},
googleCloud: {
tag: 'GOOGLE_CLOUD_LOCAL'
}
},
fileStorage: defaultEnvironmentConfigurations.fileStorage,

mail: {
gmail: {
tag: 'GMAIL_LOCAL'
},
yahoo: {
tag: 'YAHOO_LOCAL'
},
outlook: {
tag: 'OUTLOOK_LOCAL'
}
},
mail: defaultEnvironmentConfigurations.mail,

sms: {
twillio: {
tag: 'TWILLIO_LOCAL'
},
awsSns: {
tag: 'AWS_SNS_LOCAL'
}
},
sms: defaultEnvironmentConfigurations.sms,

analytics: {
googleAnalytics: {
tag: '',
id: ''
},
matomo: {
tag: '',
id: ''
},
mixPanel: {
tag: '',
id: ''
}
}
analytics: defaultEnvironmentConfigurations.analytics
};
76 changes: 7 additions & 69 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,25 @@
import { EnvironmentModel } from '../app/model/environment/environment.model';
import { defaultEnvironmentConfigurations } from './environment-init';

export const environment: EnvironmentModel = {
identity: 'production',

production: true,

// TODO: Change after heroku fix
// serverUrl: 'https://oth-server-orchestra-live.herokuapp.com',
// serverUrl: 'https://oth-server-orchestra-live.herokuapp.com',
serverUrl: 'https://oth-server-orchestra-dev.herokuapp.com',

clientUrl: 'https://opentemplatehub.com',

oauth: {
twitter: {
tag: 'TWITTER'
},
google: {
tag: 'GOOGLE'
},
facebook: {
tag: 'FACEBOOK'
},
linkedin: {
tag: 'LINKEDIN'
},
twitch: {
tag: 'TWITCH'
},
github: {
tag: 'GITHUB'
},
dribbble: {
tag: 'DRIBBBLE'
},
reddit: {
tag: 'REDDIT'
}
},
oauth: defaultEnvironmentConfigurations.oauth,

payment: {
stripe: {
tag: 'STRIPE',
publishableKey: 'pk_test_51I4pFdJslj2vUcp7AkRtYwCPiZJbSvGK7lNFggSbLp9LQopdnUJU44mBKlREonmvszmASnyv4FMxQztzFedllxJO00wg7mHS85',
},
coinbase: {
tag: 'COINBASE'
},
paypal: {
tag: 'PAYPAL',
clientId: 'AZDxjDScFpQtjWTOUtWKbyN_bDt4OgqaF4eYXlewfBP4-8aqX3PiV8e1GWU6liB2CUXlkA59kJXE7M6R',
env: 'live'
}
},
payment: defaultEnvironmentConfigurations.payment,

fileStorage: {
aws: {
tag: 'AWS'
},
googleCloud: {
tag: 'GOOGLE_CLOUD'
}
},
fileStorage: defaultEnvironmentConfigurations.fileStorage,

mail: {
gmail: {
tag: 'GMAIL'
},
yahoo: {
tag: 'YAHOO'
},
outlook: {
tag: 'OUTLOOK'
}
},
mail: defaultEnvironmentConfigurations.mail,

sms: {
twillio: {
tag: 'TWILLIO'
},
awsSns: {
tag: 'AWS_SNS'
}
},
sms: defaultEnvironmentConfigurations.sms,

analytics: {
googleAnalytics: {
Expand Down
Loading

0 comments on commit 547f7be

Please sign in to comment.