Я пытаюсь развернуть приложение в Heroku.Он собирается правильно (с помощью пакета сборки heroku nodejs), но я не могу получить доступ к переменным окружения Heroku.Это используемый файл среды:
import * as process from 'process'
console.log(process); // Object containing numerous props (cwd, chdir, browser, etc.)
console.log(process.env); // Empty object but NOT undefined
console.log(process.env.BACKEND_URL); // Undefined
export const environment = {
production: true,
baseUrl: process.env.BACKEND_URL,
apiBaseUrl: process.env.BACKEND_URL + '/api/v1/',
cmsBaseUrl: process.env.BACKEND_URL + '/content/pages/',
verboseApiCalls: false
};
Выполняемая команда построения:
"postinstall": "ng build --aot --prod && npm install -g serve",
Angular.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"front-end": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/front-end",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"stylePreprocessorOptions": {
"includePaths": [
"src/assets/styles/partials"
]
},
"styles": [
"src/styles-app-loading.scss",
"src/assets/styles/catch.scss",
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
},
"local": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.local.ts"
}
],
"optimization": false,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": false
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "front-end:build",
"disableHostCheck": true
},
"configurations": {
"production": {
"browserTarget": "front-end:build:production"
},
"local": {
"browserTarget": "front-end:build:local"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "front-end:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.css"
],
"stylePreprocessorOptions": {
"includePaths": [
"src/assets/styles/partials"
]
},
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"front-end-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "front-end:serve"
},
"configurations": {
"production": {
"devServerTarget": "front-end:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "front-end"
}
Package.json: (на самом деле не знаю, уместно ли это)
{
"name": "front-end",
"version": "0.1.0",
"scripts": {
"ng": "ng",
"build": "ng build",
"test": "ng test",
"postinstall": "ng build --aot --prod && npm install -g serve",
"start": "serve dist/front-end/ -l $PORT",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.1.3",
"@angular/cdk": "^7.1.1",
"@angular/cli": "~7.1.2",
"@angular/common": "^7.1.3",
"@angular/compiler": "^7.1.3",
"@angular/core": "^7.1.3",
"@angular/flex-layout": "^7.0.0-beta.21",
"@angular/forms": "^7.1.3",
"@angular/http": "^7.1.3",
"@angular/material": "^7.1.1",
"@angular/platform-browser": "^7.1.3",
"@angular/platform-browser-dynamic": "^7.1.3",
"@angular/router": "^7.1.3",
"@swimlane/ngx-charts": "^10.0.0",
"classlist.js": "^1.1.20150312",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"typescript": "~3.1.6",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.13.2",
"@angular/cli": "~7.1.2",
"@angular/compiler-cli": "^7.2.5",
"@angular/language-service": "^7.1.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-spec-reporter": "0.0.32",
"protractor": "^5.4.1",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~3.1.6"
},
"engines": {
"node": "10.3.0"
}
}
Я попытался этот ответ, но нигде не смог найти упомянутые модули.Я действительно не знаю, где искать, поэтому любая помощь будет признательна.