Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web prefix for UI #139

Merged
merged 4 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker/tranql-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ WORKDIR /
RUN apk add nodejs npm git
WORKDIR /tranql/web
RUN npm install
# This lets us build index.html as a jinja template so static file references
# such as css and js can be served properly when tranql is served behind proxy
ENV PUBLIC_URL={{web_prefix}}
RUN node --max-old-space-size=4000 ./node_modules/react-scripts/scripts/build.js
RUN ln -s /tranql/web/build/static/ /tranql/tranql/static
RUN apk del nodejs npm git
Expand Down
6 changes: 4 additions & 2 deletions docker/tranql-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM python:3.7.3-alpine

ARG BRANCH=master

WORKDIR /

RUN apk add git build-base linux-headers zeromq zeromq-dev
RUN apk add git build-base linux-headers zeromq zeromq-dev libxslt-dev
RUN pip install --upgrade pip
#COPY requirements.txt ./
#RUN pip install --no-cache-dir -r ./requirements.txt
RUN git clone https://github.com/NCATS-Tangerine/tranql.git
RUN git clone --single-branch --branch ${BRANCH} https://github.com/NCATS-Tangerine/tranql.git
#RUN grep -v mysql tranql/tranql/requirements.txt > r
#RUN mv r tranql/tranql/requirements.txt
RUN pip install --no-cache-dir -r tranql/tranql/requirements.txt
Expand Down
12 changes: 7 additions & 5 deletions tranql/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import yaml
import jsonschema
import requests
from flask import Flask, request, abort, Response, send_from_directory
from flask import Flask, request, abort, Response, send_from_directory, render_template, make_response
from flask_restful import Api, Resource
from flasgger import Swagger
from flask_cors import CORS
Expand All @@ -25,7 +25,7 @@
WEB_PREFIX = os.environ.get('WEB_PATH_PREFIX', '')
WEB_PREFIX = f"/{ WEB_PREFIX.strip('/') }" if WEB_PREFIX else ''

app = Flask(__name__)
app = Flask(__name__, template_folder=web_app_root)

api = Api(app)
CORS(app)
Expand Down Expand Up @@ -143,7 +143,7 @@ def get(self):
#api.add_resource(WebAppRoot, '/', endpoint='webapp_root')

class WebAppPath(Resource):
def get(self, path):
def get(self, path, web_prefix):
"""
Web app path
---
Expand All @@ -157,6 +157,8 @@ def get(self, path):
description: Resource path.
"""
logger.error (f"........................PATH: {path}")
if path.endswith('index.html'):
return make_response(render_template(path, web_prefix=web_prefix),200)
if path != "" and os.path.exists(web_app_root + "/" + path):
return send_from_directory (web_app_root, filename=path)
else:
Expand Down Expand Up @@ -753,8 +755,8 @@ def post(self):
api.add_resource(ParseIncomplete, f'{WEB_PREFIX}/tranql/parse_incomplete')
api.add_resource(ReasonerURLs, f'{WEB_PREFIX}/tranql/reasonerURLs')

api.add_resource(WebAppPath, f'{WEB_PREFIX}/<path:path>', endpoint='webapp_path')
api.add_resource(WebAppPath, f'{WEB_PREFIX}/', endpoint='webapp_root', defaults={'path': 'index.html'})
api.add_resource(WebAppPath, f'{WEB_PREFIX}/<path:path>', endpoint='webapp_path', defaults={'web_prefix': WEB_PREFIX})
api.add_resource(WebAppPath, f'{WEB_PREFIX}/', endpoint='webapp_root', defaults={'path': f'index.html', 'web_prefix': WEB_PREFIX})

if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error')
Expand Down
5 changes: 4 additions & 1 deletion tranql/tranql_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,10 @@ def execute (self, interpreter, context={}):
import asyncio
answer = asyncio.run(graph_interface.answer_trapi_question(question['message']['query_graph']))
response = {'message': answer}

# Adds source db as reasoner attr in nodes and edges.
self.decorate_result(response['message'], {
"schema": self.service
})
elif self.service == "/schema":
result = self.execute_plan (interpreter)
else:
Expand Down
3 changes: 2 additions & 1 deletion web/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class App extends Component {
this.tranqlURL = "http://localhost:8001";
}
if(process.env.NODE_ENV === 'production') {
this.tranqlURL = window.location.origin;
// behind proxy this would treat the path used to load index.html as root
this.tranqlURL = window.location.href;
}
//this.tranqlURL = window.location.origin;
//this.tranqlURL = "http://localhost:8001"; // dev only
Expand Down