使用Python Flask,AngularJS,测试/生产目录和服务请求

时间:2013-10-12 08:04:46

标签: python angularjs heroku flask

以下是设置:

使用ngBoilerplate(grunt,bower,angular,works ......)创建SAP应用程序。在我的localhost上,它启动了一个NodeJS服务器,以便我可以测试该应用程序。这一切都很好,减去数据库/ apis。使用Grunt,它将创建一个/ build文件夹(这是所有非缩小的源,资产,用于调试)和带有生产代码的/ bin文件夹。

对于后端,我在Heroku上有一个Python烧瓶应用程序(我将用于REST API)。在Python主脚本中:

@app.route("/")
def index():
    #index.html has the angular SAP
    return make_response( open('build/index.html').read() )

我将代码推送到Heroku,它检测到一个Python应用程序(我认为这很好,因为我需要Python来发出我的api请求),并且它提供了正确的index.html。我看到Angular向/vendor/angular.js /css/angular.css等发出请求,当这些文件技术上存在于/build/vendor/angular.js时。

我不确定我是否想告诉Angular在哪里获取文件或者它是否与Python相关。

我想在LAMP土地上改变DOCROOT(WWW)吗? 我是否在Angular中更改routeprovider / urlrouterprovider以告诉它将文件提供给其他位置? 或者我是否改变了我在Python中所做的事情?

项目目录如下:

hellworld.py
requirements.txt
runp-heroku.py
procfile
Gruntfile.js
build/       //test code
  assets/
  index.html
  vendor/
bin/         //production code
  assets/
  index.html
  vendor/
src/         //original code
  assets/
  index.html
  vendor/

1 个答案:

答案 0 :(得分:0)

我从未使用过Heroku,我通常会在云端的某处获取Ubuntu服务器并手动设置生产。但重点是您的生产与开发不同,您需要一个独特的生产配置。您有两种选择:

  • 配置Flask的static_path
  • 或者将nginx配置为使用右侧目录构建的js / css