Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

node.js - After heroku deploy, my app still uses my environment values for development

I have angular app which is deployed on heroku. I am using bilding first my app with

ng build --prod

and after that i am serving the created index.html file in the dist folder and deploy on heroku.

var express = require('express');
var app = express();
var path = require('path');
const PORT = process.env.PORT || 5000;
var app_path = './dist/trucks-app';
app.use(express.static(path.join(__dirname, app_path)))
.get('*', (req,res) => res.sendFile(path.join(__dirname,app_path + '/index.html')))
.listen(PORT, () => console.log("listenin on port"));

In angular i have two environment files. One for development and one for production.

environment.ts ( development )

export const environment = {
  production: false,
  apiUrl: 'http://localhost:8000/v1/api'
};

environment.prod.ts ( production )

export const environment = {
  production: false,
  apiUrl: 'MY_HOSTED_BACKEND_URL'
};

if i test my app locally with heroku

heroku local

or with http-server

http-server command in the disted angular folder created with ng build --prod

through my console logs in the code i can see that it uses the values from the environemnt.prod.ts ( production ) file.

But after my deploy on heroku

git push heroku master

my app works, i don't have any errors. But when i open my app in the browser there i see that it uses the environemnt.ts ( development ) file.

Why is that ?

I want to mention that when i run git push heroku master i get logs that is uses production

$ git push heroku master
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 4 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 474 bytes | 237.00 KiB/s, done.
Total 6 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-18 stack
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:
remote: -----> Installing binaries

...

question from:https://stackoverflow.com/questions/65874597/after-heroku-deploy-my-app-still-uses-my-environment-values-for-development

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...