mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
add template file, update readme, remove logs
This commit is contained in:
51
README.md
51
README.md
@@ -79,39 +79,46 @@ Installing
|
||||
|
||||
Default configuration file is located in `src/environments/` folder.
|
||||
|
||||
To change the default configuration values, create local files that override the parameters you need to change:
|
||||
To change the default configuration values, create local files that override the parameters you need to change. You can use `environment.template.ts` as a starting point.
|
||||
|
||||
- Create a new `environment.dev.ts` file in `src/environments/` for `development` environment;
|
||||
- Create a new `environment.prod.ts` file in `src/environments/` for `production` environment;
|
||||
- Create a new `environment.dev.ts` file in `src/environments/` for a `development` environment;
|
||||
- Create a new `environment.prod.ts` file in `src/environments/` for a `production` environment;
|
||||
|
||||
To use the configuration parameters in your component:
|
||||
|
||||
```bash
|
||||
import { environment } from '../environment.ts';
|
||||
```
|
||||
|
||||
This file is generated by the script located in `scripts/set-env.ts`.
|
||||
|
||||
The server settings can be overwritten using an environment file.
|
||||
The server settings can also be overwritten using an environment file.
|
||||
|
||||
This file should be called `.env` and be placed in the project root.
|
||||
|
||||
The following settings can be overwritten in this file:
|
||||
|
||||
```
|
||||
DSPACE_HOST // The host name of the angular application
|
||||
DSPACE_PORT // The port number of the angular application
|
||||
DSPACE_NAMESPACE // The namespace of the angular application
|
||||
DSPACE_SSL // Whether the angular application uses SSL [true/false]
|
||||
```bash
|
||||
DSPACE_HOST # The host name of the angular application
|
||||
DSPACE_PORT # The port number of the angular application
|
||||
DSPACE_NAMESPACE # The namespace of the angular application
|
||||
DSPACE_SSL # Whether the angular application uses SSL [true/false]
|
||||
|
||||
DSPACE_REST_HOST // The host name of the REST application
|
||||
DSPACE_REST_PORT // The port number of the REST application
|
||||
DSPACE_REST_NAMESPACE // The namespace of the REST application
|
||||
DSPACE_REST_SSL // Whether the angular REST uses SSL [true/false]
|
||||
DSPACE_REST_HOST # The host name of the REST application
|
||||
DSPACE_REST_PORT # The port number of the REST application
|
||||
DSPACE_REST_NAMESPACE # The namespace of the REST application
|
||||
DSPACE_REST_SSL # Whether the angular REST uses SSL [true/false]
|
||||
```
|
||||
|
||||
The same settings can also be overwritten by setting system environment variables instead, E.g.:
|
||||
```export DSPACE_HOST=https://dspace7.4science.cloud/server```
|
||||
```bash
|
||||
export DSPACE_HOST=https://dspace7.4science.cloud/server
|
||||
```
|
||||
|
||||
The priority works as follows: **environment variable** overrides **variable in `.env` file** overrides **`environment.(prod, dev or test).ts`** overrides **`environment.common.ts`**
|
||||
|
||||
|
||||
#### Using environment variables in code
|
||||
To use environment variables in a UI component, use:
|
||||
|
||||
```typescript
|
||||
import { environment } from '../environment.ts';
|
||||
```
|
||||
|
||||
This file is generated by the script located in `scripts/set-env.ts`. This script will run automatically before every build, or can be manually triggered using the appropriate `config` script in `package.json`
|
||||
|
||||
|
||||
Running the app
|
||||
---------------
|
||||
|
@@ -19,12 +19,15 @@ switch (environment) {
|
||||
case '--prod':
|
||||
case '--production':
|
||||
production = true;
|
||||
console.log(`Building ${colors.red.bold(`production`)} environment`);
|
||||
environmentFilePath = '../src/environments/environment.prod.ts';
|
||||
break;
|
||||
case '--test':
|
||||
console.log(`Building ${colors.blue.bold(`test`)} environment`);
|
||||
environmentFilePath = '../src/environments/environment.test.ts';
|
||||
break;
|
||||
default:
|
||||
console.log(`Building ${colors.green.bold(`development`)} environment`);
|
||||
environmentFilePath = '../src/environments/environment.dev.ts';
|
||||
}
|
||||
|
||||
@@ -49,13 +52,11 @@ function generateEnvironmentFile(file: GlobalConfig): void {
|
||||
file.production = production;
|
||||
buildBaseUrls(file);
|
||||
const contents = `export const environment = ` + JSON.stringify(file);
|
||||
console.log(colors.magenta('The file `environment.ts` will be written with the following content: \n'));
|
||||
console.log(colors.grey(contents));
|
||||
writeFile(targetPath, contents, (err) => {
|
||||
if (err) {
|
||||
throw console.error(err);
|
||||
} else {
|
||||
console.log(colors.magenta(`Angular environment.ts file generated correctly at ${targetPath} \n`));
|
||||
console.log(`Angular ${colors.bold('environment.ts')} file generated correctly at ${colors.bold(targetPath)} \n`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -85,8 +86,6 @@ function createServerConfig(host?: string, port?: string, nameSpace?: string, s
|
||||
function buildBaseUrls(config: GlobalConfig): void {
|
||||
for (const key in config) {
|
||||
if (config.hasOwnProperty(key) && config[key].host) {
|
||||
console.log(key);
|
||||
console.log(config[key]);
|
||||
config[key].baseUrl = [
|
||||
getProtocol(config[key].ssl),
|
||||
getHost(config[key].host),
|
||||
|
10
src/environments/environment.template.ts
Normal file
10
src/environments/environment.template.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const environment = {
|
||||
/**
|
||||
* TODO add the sections from environment.common.ts you want to override here
|
||||
* e.g.
|
||||
* rest: {
|
||||
* host: 'rest.api',
|
||||
* nameSpace: '/rest/api',
|
||||
* }
|
||||
*/
|
||||
};
|
Reference in New Issue
Block a user