JSON API, flask server#24
Conversation
…ate the service worker
…pect rest to be string of comma-separated values
pkienzle
left a comment
There was a problem hiding this comment.
Both the flask version and the pyodide version work. Need to update the readme and fix the sed commands in deploy_calculator.sh before merging.
I didn't test the deploy workflow.
deploy_calculator.sh
Outdated
|
|
||
| # Write replacements in template | ||
| sed -i "s@{{ api_script }}@api_webworker.js@g" $TARGET_DIR/index.html | ||
| sed -i "s@{{ periodictable_version }}@$PERIODICTABLE_VERSION@g" $TARGET_DIR/index.html No newline at end of file |
There was a problem hiding this comment.
This fails on mac. sed -i is expecting an extension such as .bak to save the intermediates.
An alternative approach is to use sed on the source file and redirect output to target:
diff --git a/deploy_calculator.sh b/deploy_calculator.sh
index 149e045..4b97ea3 100755
--- a/deploy_calculator.sh
+++ b/deploy_calculator.sh
@@ -7,7 +7,6 @@ TARGET_DIR=${TARGET_DIR:-/var/www/html/resources/activation}
# Now copy all the necessary files to the target directory for deployment:
mkdir -p $TARGET_DIR
-cp activation/index_template.html $TARGET_DIR/index.html
cp activation/jquery* $TARGET_DIR/
cp activation/*.js $TARGET_DIR/
cp activation/webworker.js $TARGET_DIR/
@@ -21,5 +20,6 @@ cp -r activation/css $TARGET_DIR/
PERIODICTABLE_VERSION=$(python -c "import periodictable; print(periodictable.__version__)")
# Write replacements in template
-sed -i "s@{{ api_script }}@api_webworker.js@g" $TARGET_DIR/index.html
-sed -i "s@{{ periodictable_version }}@$PERIODICTABLE_VERSION@g" $TARGET_DIR/index.html
\ No newline at end of file
+API_SUB="s@{{ api_script }}@api_webworker.js@g"
+VER_SUB="s@{{ periodictable_version }}@$PERIODICTABLE_VERSION@g"
+sed -e "$API_SUB;$VER_SUB" activation/index_template.html > "$TARGET_DIR/index.html"There was a problem hiding this comment.
I hadn't really anticipated anyone deploying a server on a mac-based platform, but this is a good suggestion for local testing!
| The web page uses the date of activate/index.html to show the last | ||
| modification date on the program, so be sure to preserve attributes in copy. | ||
| The activation web frontend is in the activation subdirectory. | ||
| The backend API is in the cgi-bin folder (nact.py) |
There was a problem hiding this comment.
Need pyodide instructions. Something like:
You can make a serverless install using pyodide to run the backend API. The `deploy_calculator.sh`
script will install to `/var/html/resources/activation/index.html`.
To test the pyodide version before deploying, install into a temporary directory:
```sh
TARGET_DIR=/tmp/pt bash deploy_calculator.sh
(cd /tmp/pt && python -m http.server)
```
You can then navigate to http://localhost:8000/index.html to view the application.|
Add activation/pyodide and activation/periodictable_wheel_name.txt to .gitignore. |
|
Help needs updating. The changes are in #22 but I doubt it will merge cleanly after the reshuffle. |
This PR:
cgi_callfunction that works directly with a CGI request object, with a dict-basedapi_callfunctionindex_template.htmlsedstatements indeploy.shscript