You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

angular-server-side-configuration

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-server-side-configuration - npm Package Compare versions

Comparing version

to
0.0.6

2

package.json
{
"name": "angular-server-side-configuration",
"version": "0.0.5",
"version": "0.0.6",
"description": "Configure an angular application on the server",

@@ -5,0 +5,0 @@ "main": "./src/main.js",

@@ -11,3 +11,4 @@ # angular-server-side-configuration

to search for usages in bundled angular files and a script for inserting populated
environment variables into index.html file(s).
environment variables into index.html file(s) (Missing environment variables will
be represented by null). This should be done on the host serving the bundled angular files.

@@ -71,3 +72,16 @@ ### AOT

```
## Documentation
### process
Import this in polyfill.ts. This will enable the typings for process.env.*
in the code and register a fallback value for process.env.
### EnvironmentVariablesConfiguration
#### Constructor
Accepts an array of environment variables.
```typescript
const envVariables = new EnvironmentVariablesConfiguration(['PROD', 'API_ADDRESS']);
```
#### EnvironmentVariablesConfiguration.searchEnvironmentVariables

@@ -78,3 +92,80 @@ By default the searchEnvironmentVariables method uses a regex

Returns an instance of EnvironmentVariablesConfiguration.
```typescript
const envVariables: EnvironmentVariablesConfiguration =
EnvironmentVariablesConfiguration.searchEnvironmentVariables(bundledAngularFilesRoot);
```
#### EnvironmentVariablesConfiguration.prototype.populateVariables
Generates an object, with the environment variable names being the key and
the actual values being the values. Missing environment variables will be represented by null.
```typescript
const envVariables = new EnvironmentVariablesConfiguration(['PROD', 'API_ADDRESS']);
process.env.API_ADDRESS = 'https://example-api.com';
const variables = envVariables.populateVariables();
// { PROD: null, API_ADDRESS: 'https://example-api.com' }
```
#### EnvironmentVariablesConfiguration.prototype.generateIIFE
Generates the IIFE in which the environment variables are assigned to window.process.env.
```typescript
const envVariables = new EnvironmentVariablesConfiguration(['PROD', 'API_ADDRESS']);
process.env.API_ADDRESS = 'https://example-api.com';
const iife = envVariables.generateIIFE();
// (function(self){self.process={env:{"PROD":null,"API_ADDRESS":"https://example-api.com"};})(window)
```
#### EnvironmentVariablesConfiguration.prototype.apply
Inserts the discovered environment variables as an IIFE wrapped in a script tag
into the specified file content without saving the file.
`file` The file to be read.
`options` Optional options for insertion.
`options.insertionRegex` The replacement pattern, where the configuration should be inserted
(Defaults to /<!--\s*CONFIG\s*-->/).
Returns a promise, which resolves to the file content with the environment variables inserted.
```typescript
const envVariables = EnvironmentVariablesConfiguration.searchEnvironmentVariables(bundledAngularFilesRoot);
const content = await envVariables.apply(pathToIndexHtml);
// <html>...<script>(function(self){self.process={env:{"PROD":null,"API_ADDRESS":"https://example-api.com"};})(window)</script>...</html>
```
#### EnvironmentVariablesConfiguration.prototype.insertAndSave
Inserts the discovered environment variables as an IIFE wrapped in a script tag into the specified file.
`file` The file into which the environment variables should be inserted.
`options` Optional options for insertion.
`options.insertionRegex` The replacement pattern, where the configuration should be inserted
(Defaults to /<!--\s*CONFIG\s*-->/).
Returns a promise, which resolves after the enivornment variables have been saved to the given file.
```typescript
const envVariables = EnvironmentVariablesConfiguration.searchEnvironmentVariables(bundledAngularFilesRoot);
await envVariables.insertAndSave(pathToIndexHtml);
```
#### EnvironmentVariablesConfiguration.prototype.insertAndSave
Inserts the discovered enviornment variables as an IIFE wrapped in a script tag into the matched files.
`root` The root directory from which to search insertion files.
`options` Optional options for insertion.
`options.filePattern` The file pattern in which the configuration should be inserted
(Defaults to /index.html$/).
`options.insertionRegex` The replacement pattern, where the configuration should
be inserted (Defaults to /<!--\s*CONFIG\s*-->/).
Returns a promise, which resolves after the environment variables have been inserted to all matched files.
```typescript
const envVariables = EnvironmentVariablesConfiguration.searchEnvironmentVariables(bundledAngularFilesRoot);
await envVariables.insertAndSaveRecursively(bundledAngularFilesRoot);
```
## License
Apache License, Version 2.0