From 56dcde5a043de7ada889748fa296415c28e972e9 Mon Sep 17 00:00:00 2001 From: Jeroen Hermans Date: Thu, 8 Nov 2018 10:09:42 +0100 Subject: [PATCH] Enable using browser history and update server dependencies Now routes don't come after the hash of the index file in the static folder, instead just following the root of the subdomain. Instead of manually saving to the URL to copy it, the URL updates automatically and is added to your browser history (without page reload). --- app/__init__.py | 9 +++++++-- app/static/index.js | 1 + app/static/src/editor.vue | 17 ++++++++++------- requirements.txt | 4 ++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 45ec197..13f6d54 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -4,7 +4,7 @@ app = Flask(__name__) app.config.from_object('config') -app.wsgi_app = WhiteNoise(app.wsgi_app, root='app/static/', prefix='static/') +app.wsgi_app = WhiteNoise(app.wsgi_app, root='app/static/', prefix='/', index_file=True) # Helper funcs ---------------------------------------------------------------- from antlr_plsql import plsql_grammar, ast as plsql_ast @@ -47,7 +47,7 @@ def get_ast(code, start, parser_name): return None # Views ----------------------------------------------------------------------- -from flask import Flask, request, url_for, redirect, jsonify, make_response +from flask import Flask, request, url_for, redirect, jsonify, make_response, send_file import yaml @@ -104,3 +104,8 @@ def ast_from_config(): out[k] = [{'code': code, 'ast': json_ast} for code, json_ast in zipped] print(out) return jsonify(out) + + +@app.errorhandler(404) +def page_not_found(error): + return send_file('./static/index.html') diff --git a/app/static/index.js b/app/static/index.js index 86e087b..233e7d8 100644 --- a/app/static/index.js +++ b/app/static/index.js @@ -12,6 +12,7 @@ const routes = [ ] const router = new VueRouter({ + mode: 'history', routes }) diff --git a/app/static/src/editor.vue b/app/static/src/editor.vue index 19a894f..67f0ac3 100644 --- a/app/static/src/editor.vue +++ b/app/static/src/editor.vue @@ -3,7 +3,7 @@

     
- parser: + parser: start: -
- - + @@ -35,7 +33,7 @@ var graphs = require('./graphs.js') var request = require('superagent') var grammars = [ - { + { name: 'plsql', start: 'sql_script', show_parse: true @@ -95,8 +93,8 @@ export default { crntGrammar () { return this.grammars.filter(({name}) => name == this.grammarName)[0]}, }, watch: { - codeData () { - this.getAst() + codeData () { + this.getAst() }, }, methods: { @@ -143,6 +141,11 @@ export default { this.parserStart = this.crntGrammar.start }, + submit () { + this.parseCode() + this.routeToCode() + }, + setupEditor(editor) { editor.setTheme("ace/theme/tomorrow_night_eighties"); editor.session.setMode("ace/mode/sql"); diff --git a/requirements.txt b/requirements.txt index 58b246e..0a45366 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ gunicorn==19.7.1 gevent==1.2.1 -Flask==0.12.1 -whitenoise==3.3.1 +Flask==1.0.2 +whitenoise==4.1 PyYAML==3.12 antlr4-python3-runtime==4.7.1