Skip to content

JSON API, flask server#24

Open
bmaranville wants to merge 69 commits intopython-periodictable:masterfrom
bmaranville:deduplicate-html
Open

JSON API, flask server#24
bmaranville wants to merge 69 commits intopython-periodictable:masterfrom
bmaranville:deduplicate-html

Conversation

@bmaranville
Copy link
Contributor

This PR:

  • replaces the cgi_call function that works directly with a CGI request object, with a dict-based api_call function
  • removes the CGI demo server
  • adds a Flask demo server
  • replaces duplicate HTML files with a single index_template.html
    • rendered with built-in renderer in flask server
    • rendered with sed statements in deploy.sh script

Copy link
Contributor

@pkienzle pkienzle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pkienzle
Copy link
Contributor

Add activation/pyodide and activation/periodictable_wheel_name.txt to .gitignore.

@pkienzle
Copy link
Contributor

Help needs updating. The changes are in #22 but I doubt it will merge cleanly after the reshuffle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants