69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
from flask import Flask, request
|
|
from Gateway import *
|
|
from Route import *
|
|
from ExceptionHandler import *
|
|
|
|
class GatewayServer():
|
|
def __init__(self):
|
|
self.app = Flask('gateway')
|
|
self.url_map = {
|
|
'test': 'http://127.0.0.1:7777',
|
|
'music_server': 'http://192.168.124.12:4533'
|
|
}
|
|
self.url_supplier = lambda x: self.url_map[x]
|
|
|
|
route_2 = {
|
|
"name": "add-sound",
|
|
"service_name": "music_server",
|
|
"methods": ["POST"],
|
|
"path": "/music/api/playlist/<playlist_id>/tracks",
|
|
"upstream_path": "/api/playlist/<playlist_id>/tracks",
|
|
"pipelines": {
|
|
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
|
}
|
|
}
|
|
|
|
route_3 = {
|
|
"name": "del-sound",
|
|
"service_name": "music_server",
|
|
"methods": ["DELETE"],
|
|
"path": "/music/api/playlist/<playlist_id>/tracks",
|
|
"upstream_path": "/api/playlist/<playlist_id>/tracks",
|
|
"pipelines": {
|
|
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
|
}
|
|
}
|
|
|
|
route_4 = {
|
|
"name": "del-playlist",
|
|
"service_name": "music_server",
|
|
"methods": ["DELETE"],
|
|
"path": "/music/api/playlist/<playlist_id>",
|
|
"upstream_path": "/api/playlist/<playlist_id>",
|
|
"pipelines": {
|
|
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
|
}
|
|
}
|
|
|
|
route_5 = {
|
|
"name": "add-playlist",
|
|
"service_name": "music_server",
|
|
"methods": ["POST"],
|
|
"path": "/music/api/playlist",
|
|
"upstream_path": "/api/playlist",
|
|
"pipelines": {
|
|
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
|
}
|
|
}
|
|
|
|
self.routes = Route.load([route_2, route_3, route_4, route_5])
|
|
|
|
gateway = GenericGateway(self.app, self.routes, url_supplier=self.url_supplier)
|
|
gateway.register_routes()
|
|
|
|
gateway_server = GatewayServer()
|
|
app = gateway_server.app
|
|
# app.run(port=15000, host="192.168.124.12", debug=True)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True) |