AngularJS フロントエンド + GAE バックエンド (Python と Flask) を使用してアプリを開発しています。Flask-Restless エクステンションで作成した API エンドポイントをルーティングするための app.yaml の設定に問題があります。私の app.yaml ファイルは次のようになります。
application: myAppID
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
# handler 1
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
# handler 2
- url: /api/.*
script: main.app
# handler 3
- url: /test
script: main.app
# handler 4
- url: (.*)/
static_files: app\1/index.html
upload: app #this is the frontend folder for Angular
# handler 5
- url: (.*)
static_files: app\1
upload: app #this is the frontend folder for Angular
Angular では、ルート構成は次のようになります。
App.config(['$stateProvider', '$locationProvider', '$urlRouterProvider', 'RouteHelpersProvider',
function ($stateProvider, $locationProvider, $urlRouterProvider, helper) {
'use strict';
$locationProvider.html5Mode(false);
// default route
$urlRouterProvider.otherwise('/app/dashboard');
// other routes ...
}]);
main.py ファイルは次のようになります。
from flask import Flask
import os
from werkzeug import debug
from flask import jsonify
from google.appengine.ext.webapp.util import run_wsgi_app
app = Flask('myApp')
if os.getenv('SERVER_SOFTWARE') and os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/'):
app.debug = False
else:
app.debug = True
if app.debug:
app.wsgi_app = debug.DebuggedApplication(app.wsgi_app, True)
@app.route('/test')
def test():
return jsonify(test={"json": "test"})
import models
run_wsgi_app(app)
models
Flask-SQLAlchemy モデルと Flask-Restless エンドポイントを含むファイルです。
Angular パーツは正しく読み込まれます。たとえば、次の URL は正常に機能します。
A) http://localhost:8080/#/app/dashboard
しかし、GAE バックエンド部分は、次のような URL に対して 500 エラーで応答します。
B) http://localhost:8080/api/person
C) http://localhost:8080/test
を削除すると URL は正常に機能しhandler 4
ますhandler 5
が、Angular フロントエンドは機能しなくB
なります。C
私が間違っていることは何ですか?