Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带角度前端的Python API服务器_Python_Angularjs_Python 3.x_Api - Fatal编程技术网

带角度前端的Python API服务器

带角度前端的Python API服务器,python,angularjs,python-3.x,api,Python,Angularjs,Python 3.x,Api,我用Angularjs前端和API后端构建了一个应用程序已经有一段时间了,所以如果这是一个相当愚蠢的问题,请原谅我。我想运行一个提供API的Python后端。每个端点都应该以/api/开头。现在此应用程序在文件夹“api”中运行,这是我的文件夹结构: -api/ -- controllers/ -- __init__.py -config/ -public/ -- assets/ -- index.html -server.py 现在我想知道如何运行一个Web服务器,当我使用一个以/api开头

我用Angularjs前端和API后端构建了一个应用程序已经有一段时间了,所以如果这是一个相当愚蠢的问题,请原谅我。我想运行一个提供API的Python后端。每个端点都应该以
/api/
开头。现在此应用程序在文件夹“api”中运行,这是我的文件夹结构:

-api/
-- controllers/
-- __init__.py
-config/
-public/
-- assets/
-- index.html
-server.py
现在我想知道如何运行一个Web服务器,当我使用一个以
/api
开头的端点时,它可以访问api文件夹中的文件,而其他每个端点都应该访问我的AngularJS应用程序,该应用程序可以从公用文件夹中获得。这样,我就可以从AngularJS应用程序访问Python api端点,并且仍然非常安全修复,因为公用文件夹中没有my Python源文件

因此,AngularJS端点:
/home
/login
/logout
等等

Python API端点:
/API/user
/API/user/profile
等(以
/API/
开头的每个端点)

有什么想法吗?我可以在不同的端口上运行两台服务器,但这不应该是一种方式。我用PHP做过类似的事情,但从来没有用Python做过,不知怎的,这让我现在很头疼


如果有人能帮助我,那就太好了。

您可以使用nginx部署这个项目

server {
    listen 80;
    listen [::]:80;

    server_name xyz.com;

    root /var/www/frontend/xyz-frontend/dist;
    index index.php index.html index.htm index.nginx-debian.html;


    # handles the api requests
    location /api {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            proxy_pass http://unix:/var/www/services/xyz/api.sock;
    }

    # FOR ANGULAR BUILD
    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.html /custom_50x.html;
    }

欢迎。我认为您应该为python服务器使用一个框架。我确实,我使用Flask。我想,我对PHP所做的是,使用PHP作为API,让PHP在每个非API URL上呈现index.html。公用文件夹包含一个PHP文件(index.PHP),它只加载(
require
)一个Bootstrap.php,它位于根文件夹中。也许,为了开发,我应该能够在每个非api url上呈现index.html,作为默认值,因此angular将从那里处理url端点。我想这应该是可行的。