Skip to content

Instantly share code, notes, and snippets.

@AlexAegis
Created April 8, 2021 12:56
Show Gist options
  • Save AlexAegis/4aa97922f694eb45f9167a3fcd2c8acd to your computer and use it in GitHub Desktop.
Save AlexAegis/4aa97922f694eb45f9167a3fcd2c8acd to your computer and use it in GitHub Desktop.
Angular Generic Environment Setup
/**
* Environment shape
*/
export interface Environment {
/**
* Application version, straight from the package.json
*/
version: string;
/**
* Whether the app is in production mode or not
*/
production: boolean;
/**
* The start of the URL
*
* Example: 'http://'
*/
protocol: string;
/**
* The core of the URL
*
* Example: 'localhost'
*/
baseUrl: string;
/**
* An optional port to be appended after the baseUrl
*/
port?: number;
/**
* The prefix of the api
*
* Example: '/api/v1/'
*/
apiPrefix?: string;
}
/**
* Default environmental values, these are meant to be overridden.
*/
export const initialEnvironment: Environment = {
version: require('../../package.json').version,
production: false,
protocol: 'https://',
baseUrl: 'localhost',
apiPrefix: 'api'
};
export const domain = (environment: Environment): string =>
`${environment.baseUrl}${environment.port ? ':' + environment.port : ''}`;
export const api = (environment: Environment): string =>
`${environment.protocol}${domain(environment)}${
environment.apiPrefix ? '/' + environment.apiPrefix : ''
}`;
import { Environment, initialEnvironment } from './environment.interface';
export const environment: Environment = {
...initialEnvironment,
production: true,
baseUrl: 'url',
};
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
import { Environment, initialEnvironment } from "./environment.interface";
export const environment: Environment = {
...initialEnvironment,
protocol: 'http://',
port: 8001,
production: false,
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
import 'zone.js/dist/zone-error'; // Included with Angular CLI.
export * from './environment';
export * from './environment.interface';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment