Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

440
Visualizações
Can I serve an angular application in the same FastApi which have, of course, the Api?

I have an Api developed in FastApi framework. I have one Angular application that calls the FastApi. Due to several reasons, it would be great (network names, parameters, docker images, etc) if I could deploy the angular application in the FastApi as a simple web application. This way I could access the Api as "localhost" and the Api can be "private".

Is this possible?

thank you, José Cruz

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I don't know if it can help you but it worked for me.

I warn you that this is not a good practice but in the context I applied it solved my problem.

I have a small Angular application that login and authenticated redirection to FastAPI's Redoc and Swagger documentation.

I set up a directory with static files and put the angular build inside. In FastAPI I made an endpoint reading and serving the index.html file.

For the angular to see the files, I build Angular by passing the --base-href flag pointing to the mounted static directory.

The codes look like this:

project/
    static/
        index.html
        ... (files app angular)

    main.py

main.py

from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles


app = FastAPI()

app.mount("/static", StaticFiles(directory="static"), name="static")


@app.get('/')
def get_app_angular():

    with open('static/index.html', 'r') as file_index:
        html_content = file_index.read()
    return HTMLResponse(html_content, status_code=200)

Build APP Angular:

ng build --base-href static/ --prod

over 4 years ago · Santiago Trujillo Relatório

0

No, it is not possible as far as I know. It would be like talking two different languages. With JSON files you may be able to share configurations, but not more.

Maybe going on the low level (both python and nodejs are written in C or C++), you could bind them, but you would get much more of an overhead to do this than to simply spawn two separate containers.

Also, separating API and frontend is a good practice, which allows you to perform changes/updates in a much simpler form and to scale one service in case of sudden peaks. In addition, the security is improved, as the two containers are virtually separated and secured by the containers. Breaking into one, would not necessarily compromise the second (I said would because it depends on what access information you store and permissions you give to the former).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda