13

Development purpose I want to start my Angular application with custom-domain instead of localhost

Is any other way available?

I am able to find solutions for php but I didn't find solutions for the angular application.

6

2 Answers 2

16

Update your angular.json

This is what you should do:

"projects": { "project-name": { ... "architect": { "serve": { "options": { "host": "customdomain.baz", "port": 80 } } } } } 

Update your host file if you are on mac/ linux

go to /etc/hosts

## ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 customdomain.baz // or whatever your domain is 255.255.255.255 broadcasthost ::1 localhost 
Sign up to request clarification or add additional context in comments.

2 Comments

notice that under the same path (architect.serve.options) there's the useful allowedHosts property that receives an string[] of domains.
And for using https?
4

Add a line in hosts file:

127.0.0.1 my-custom-domain.com 

But this will require port to be specified anyway. You'll have to use my-custom-domain.com:4200.

To use default port :80, use as a reference this post

If you want to run multiple sites on the same port, but serve different domains, use Nginx or Apache as a proxy.

Here is a sample server config for nginx:

server { listen 80; server_name my-custom-domain.com; location / { proxy_pass http://localhost:4200; } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.