Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
ngx-envconfig
Advanced tools
Configuration utility for Angular app.
npm install ngx-envconfig --save
/config
folder under /assets
directory/assets/config
folder.// src/assets/config/development.json
{
"HOST_API": "http://development.server.com', <-- suppose this is your development server
"API_ENDPOINTS": {
"USER": "/api/v1/user",
...
}
}
// src/assets/config/staging.json
{
"HOST_API": "http://staging.server.com', <-- suppose this is your staging server
"API_ENDPOINTS": {
"USER": "/api/v1/user",
...
}
}
// src/assets/config/production.json
{
"HOST_API": "http://producton.server.com', <-- suppose this is your production server
"API_ENDPOINTS": {
"USER": "/api/v1/user",
...
}
}
// src/app/app.module.ts
import { NgModule } from '@angular/core';
import { ConfigModule, ConfigService } from './config/config.service';
@NgModule({
imports: [
ConfigModule.forRoot({state: 'development'})
...
],
providers: [
...
Your Providers
...
]
})
export class AppModule { }
// src/app/app.component.ts
import { Component } from '@angular/core';
import { ConfigService } from 'ngx-envconfig';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private configService: ConfigService){
console.log(configService.get('HOST_API'))
// prints: http://development.server.com
}
}
Add the following snippet to .angular-cli.json
file.
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
"staging": "environments/environment.staging.ts"
}
Create the following files under /environments
folder.
// ./environments/environment.prod.ts
export const environment = {
state: 'production'
};
// ./environments/environment.staging.ts
export const environment = {
state: 'staging'
};
// ./environments/environment.development.ts
export const environment = {
state: 'development'
};
Then you can add environment value to ConfigModule
like this:
// src/app/app.module.ts
import { NgModule } from '@angular/core';
import { ConfigModule, ConfigService } from './config/config.service';
import { environment } from '../src/environments/environment'; // <-- add this line
@NgModule({
imports: [
ConfigModule.forRoot(environment) // <-- pass environment variable
...
],
providers: [
...
Your Providers
...
]
})
export class AppModule { }
Based on the provided state
value in environment.*.ts
file it will load the approprate *.json
config file. Once the configuration *.json
file is loaded, the Angular will bootstrap the app.
ng build --env=dev
builds for development environment. This is default if you don't specify.ng build --env=staging
builds for staging environment.ng build --env=prod
builds for production environment.propertyName
config file.true
if environment is development, otherwhise false
"API_ENDPOINTS"
object in cofig file, which provides the list of available API endpoints and "HOST_API"
which is the API's host URL.FAQs
Configuration utility for Angular app based on the environment variables
We found that ngx-envconfig demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.