How to host my angular application

Asked

Viewed 1,846 times

2

I have the following directories in my angular application:

node_modules/
src/
--client/
----/app/
----/index.html
--server/
package.json

file print inserir a descrição da imagem aqui

I would like when the user accesses my site he redirects directly to src/client/index.html and hides src/client/.

What’s the best way to do it? Thanks.

  • It would be possible to post the complete tree of your directories, and your stack (boot file) of your nodejs server (I assume your backend is Node by 'node_modules/') ?

  • I don’t have any server yet, but I’ll post the rest of the tree

  • You don’t necessarily need to use Node JS to serve your application. You can use Apache, Nginx, IIS or any other webserver that suits you as the angled wheel on the client machine

1 answer

4

Using Express on top of Nodejs as server, you will do the following:

var express= require('express');
var app = express();

app.use(express.static(__dirname + '../client/app'));

app.listen(80, function () {
  console.log('Servidor rodando!');
});

Using the express.static, you will tell the server which public folder of your application. The __dirname points to the current folder. In this case, I assumed that your server will be inside the folder \server and sailed up with the two points to then enter into client/app. There, by default, it will "serve" the file with name index.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.