Skip to content
Permalink
Browse files

progress towards a package distribution

  • Loading branch information...
paulgb committed May 12, 2019
1 parent 1a6c666 commit 5c8d7c742567175cae8d8fcb85f2bd88d867991b
Showing with 47 additions and 28 deletions.
  1. +3 −1 .gitignore
  2. +1 −0 server/MANIFEST.in
  3. +7 −0 server/build.sh
  4. +21 −9 server/notify_run_server/app.py
  5. +9 −0 site/build-env.sh
  6. +0 −8 site/build.sh
  7. +2 −2 site/src/config.ts
  8. +0 −4 site/tracker.html
  9. +4 −4 site/webpack.config.js
@@ -12,4 +12,6 @@ site/dist
*.egg-info
package-lock.json
*.pyc
notify.sqlite
notify.sqlite
server/notify_run_server/static
site/tracker.html
@@ -0,0 +1 @@
recursive-include notify_run_server/static *
@@ -0,0 +1,7 @@
cd ../site

./build.sh

cd -

cp -r ../site/public notify_run_server/static
@@ -7,16 +7,25 @@
from notify_run_server.model import NoSuchChannel, NotifyModel
from notify_run_server.notify import parallel_notify
from notify_run_server.params import (API_SERVER, DB_MODEL,
VAPID_PUBKEY, WEB_SERVER)
VAPID_PUBKEY, WEB_SERVER, CHANNEL_ID_CHARS)

from werkzeug.routing import Rule, Map, BaseConverter, ValidationError

class ChannelIDConverter(BaseConverter):
def to_python(self, value):
if not all(c in set(CHANNEL_ID_CHARS) for c in value):
raise ValidationError()
return value

try:
from urllib.parse import parse_qs
except ImportError:
from urlparse import parse_qs # type: ignore


app = Flask(__name__)
app = Flask(__name__, static_url_path='')
CORS(app)
app.url_map.converters['chid'] = ChannelIDConverter

if DB_MODEL == 'boto':
from notify_run_server.model_dynamodb import DynamodbNotifyModel
@@ -60,20 +69,20 @@ def register_channel():
})


@app.route('/<channel_id>/subscribe', methods=['POST'])
@app.route('/<chid:channel_id>/subscribe', methods=['POST'])
def subscribe(channel_id):
model.add_subscription(channel_id, request.get_json())
return jsonify(dict())


@app.route('/<channel_id>/qr.svg', methods=['GET'])
@app.route('/<chid:channel_id>/qr.svg', methods=['GET'])
def get_qr(channel_id):
buffer = BytesIO()
qr_for_channel(channel_id).svg(buffer, 6)
return Response(buffer.getvalue().decode('utf-8'), mimetype='text/xml')


@app.route('/<channel_id>/info', methods=['GET'])
@app.route('/<chid:channel_id>/info', methods=['GET'])
def info(channel_id):
model.get_channel(channel_id) # Ensure the channel exists.

@@ -83,7 +92,7 @@ def info(channel_id):
})


@app.route('/<channel_id>', methods=['GET'])
@app.route('/<chid:channel_id>', methods=['GET'])
def get_channel(channel_id):
try:
channel = model.get_channel(channel_id)
@@ -98,7 +107,7 @@ def get_channel(channel_id):
return jsonify({'error': 'No such channel: {}'.format(err.channel_id)}), 404


@app.route("/<channel_id>", methods=['POST'])
@app.route("/<chid:channel_id>", methods=['POST'])
def post_channel(channel_id):
message = request.get_data(as_text=True)

@@ -128,10 +137,13 @@ def post_channel(channel_id):
return '{}'


@app.route("/")
@app.route('/')
def index():
return '{}'
return app.send_static_file('index.html')

@app.route('/c/<chid:channel_id>')
def channel(channel_id):
return app.send_static_file('channel.html')

def main():
app.run(threaded=True)
@@ -0,0 +1,9 @@
if [ -f .env ]; then
echo "Loading .env file."
set -a
source .env
else
echo "No .env found, skipping."
fi

source build.sh
@@ -9,14 +9,6 @@ rm -rf dist static public
echo "Installing environment."
npm install

if [ -f .env ]; then
echo "Loading .env file."
set -a
source .env
else
echo "No .env found, skipping."
fi

echo "Bundling JavaScript."
./node_modules/.bin/webpack --display-error-details

@@ -1,4 +1,4 @@
export namespace Config {
export const API_SERVER = process.env.NOTIFY_API_SERVER;
export const WEB_SERVER = process.env.NOTIFY_WEB_SERVER;
export const API_SERVER = process.env.NOTIFY_API_SERVER || location.origin;
export const WEB_SERVER = process.env.NOTIFY_WEB_SERVER || location.origin;
}

This file was deleted.

@@ -11,10 +11,10 @@ module.exports = {
},
devtool: "source-map",
plugins: [
new webpack.EnvironmentPlugin([
'NOTIFY_API_SERVER',
'NOTIFY_WEB_SERVER',
]),
new webpack.EnvironmentPlugin({
'NOTIFY_API_SERVER': null,
'NOTIFY_WEB_SERVER': null
}),
],
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]

0 comments on commit 5c8d7c7

Please sign in to comment.
You can’t perform that action at this time.