# How I am supposed to Deploy an app that has dinamic generated url´s?

**URL:** <https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021>\
**Category:** General\
**Created:** [December 5, 2019, 10:29pm UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021 "2019-12-05T22:29:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Onpointiscake](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/onpointiscake/32/112084_2.png) [@Onpointiscake](https://forum.freecodecamp.org/u/Onpointiscake)\
**Post date:** [December 5, 2019, 10:29pm UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021/1 "2019-12-05T22:29:51Z")

</div>

Hi there. This is my first full stack app I´m trying to deploy.  
Until now I have only deployed to the web Front End applications.

This time I have several doubts for this:

1. **First Doubt** Do I have to change the API requests urls? For example “[http://localhost/3000/api/list](http://localhost/3000/api/list)” and so on.  
I imagine I have to change the localhost/3000 part, right?

2. **Biggest doubt/ Problem** My app generates “dinamically” new urls:  
For example, my front page is this: localhost/3000  
But when an user creates a list, it generates an specific ID for that list, and it makes an specific url for that list. So anyone with that url can see it. For example:  
[www.todolist.com/list/abd031010as](http://www.todolist.com/list/abd031010as)  
(i´m already substituing the local host for my supposed domain)

will this work? One big doubt is that if for example I want to deploy it in netlify or heroku, when i deploy i need to know the domain that netlify/heroku will give me in order to put it correctly in my app. But until i deploy it i wont know the domain name LOL So how could i sort this out?

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [December 6, 2019, 12:42am UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021/2 "2019-12-06T00:42:14Z")

</div>

In response to the first question - and I guess the second - an easy way to store these as constants. One common way is in a .env file. That’s often used for secret information but you can use it for non secret information.

For example, in the my local .env file I could have a constant like:

```auto
SERVER_URL=http://localhost/3000

```

And then when I set up heroku, I can set up the environment variables. I don’t know about netify, but I’ve done it on heroku and I assume it’s pretty standard.

Then in my code, I just prepend all my urls with that.

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [December 6, 2019, 12:43am UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021/3 "2019-12-06T00:43:18Z")

</div>

But yes, this is all confusing and taking that leap from the hypothetical to the concrete is scary. Everyone goes through this. Just stick with it and ask questions. You’ll get the hang of it.

---

<div class="post-metadata">

**Author:** ![Onpointiscake](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/onpointiscake/32/112084_2.png) [@Onpointiscake](https://forum.freecodecamp.org/u/Onpointiscake)\
**Post date:** [December 6, 2019, 9:47am UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021/4 "2019-12-06T09:47:59Z")

</div>

I see! Well i think i sorted out that problem! But now I have one issue more…

First when i deployed yesterday I got a CORS ERROR and I had to change all of my requests ([http://localhost:4000](http://localhost:4000)) to https ([https://localhost:4000](https://localhost:4000)) I hope **that´s all right** So far that error stop appearing.

But then another error is that my API requests still don´t work. Do you think it could be because i hardcoded the local port in my api requests, and then in my backend i have this:

```auto
app.listen(process.env.PORT || 4000,

```

Could it be that Heroku is serving the backend in another port and that´s why my api requests are not working? If you think it could be that how can i put the correct port in the front end? This didn´t work:

```auto
 axios.post(`https://localhost:${process.env.PORT}/api/list`

```

I imagine it is the frontend can´t access environmental node variables that easily?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [December 9, 2019, 12:12am UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021/5 "2019-12-09T00:12:09Z")

</div>

> [@Onpointiscake](#):
>
> app.listen(process.env.PORT || 4000,

I would console.log _process.env.PORT_ to see what you’re getting. You may have to dig through the heroku logs.

---

<div class="post-metadata">

**Author:** ![Onpointiscake](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/onpointiscake/32/112084_2.png) [@Onpointiscake](https://forum.freecodecamp.org/u/Onpointiscake)\
**Post date:** [December 9, 2019, 5:11pm UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021/6 "2019-12-09T17:11:33Z")

</div>

It says undefined. However I learned that I just should put relative paths in the api calls , and the error doesn´t appear anymore 🙂

However, now I get again another error (request failed 503), I did “heroku logs --tail” in the console to see output errors, and I catched:

```auto
 MongoTimeoutError: Server selection timed out after 30000 ms
reason: Error: connect ECONNREFUSED 127.0.0.1:27017

```

I think it could be something related to my database. Honestly I don´t know I am supposed to have the database on the cloud and that is why it´s not working? I developed the app using mondodb locally

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [December 11, 2019, 12:37am UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021/7 "2019-12-11T00:37:26Z")

</div>

Well, I would guess that you aren’t connecting to it properly. Make sure you have the right url, username, password, etc.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 11:30am UTC](https://forum.freecodecamp.org/t/how-i-am-supposed-to-deploy-an-app-that-has-dinamic-generated-url-s/331021/8 "2021-01-16T11:30:44Z")

</div>

Closed on January 16, 2021, 11:30am UTC


