-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes: - Doc updates - More helpful error messages in several places - Add a simple Dockerfile - Fix HTTPS origin handling - Use the same Python interpreter for the downlink as launcher Fixes #1, closes #3, Better debug output to investigate #4, Fixes #7 Based-on: anvil 28d8a74b616655716ece2b2f34025cbc12332a46
- Loading branch information
Showing
19 changed files
with
293 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
let log = true; | ||
|
||
let ACTIVE_CACHE = 'v0'; | ||
let OFFLINE_TIMEOUT = 5000; | ||
|
||
let lastOffline = 0; | ||
|
||
let cleanupOldCaches = async () => { | ||
for (let key of await caches.keys()) { | ||
if (key !== ACTIVE_CACHE) { | ||
console.log("Removing old service worker cache:", key); | ||
await caches.delete(key); | ||
} | ||
} | ||
} | ||
|
||
|
||
let _fetch = async e => { | ||
|
||
let cache = await caches.open(ACTIVE_CACHE); | ||
let match = await cache.match(e.request); | ||
|
||
if (!navigator.onLine || lastOffline > Date.now() - OFFLINE_TIMEOUT) { | ||
// Shortcut: Use cache if a request recently failed for something in the cache. | ||
if (match) { | ||
log && console.log("Fast offline cache hit:", e.request.url); | ||
return match; | ||
} else { | ||
log && console.log("Fast offline cache miss:", e.request.url); | ||
} | ||
} | ||
|
||
try { | ||
let resp = await fetch(e.request.clone()); | ||
lastOffline = 0; | ||
|
||
// Allow caching anything that comes back with the X-Anvil-Cacheable header | ||
if (e.request.method === "GET" && resp.status === 200 && resp.headers.has("X-Anvil-Cacheable")) { | ||
log && console.log("Caching:", e.request.url); | ||
cache.put(e.request, resp.clone()); | ||
} else { | ||
log && console.log("Not caching:", e.request.url); | ||
cache.delete(e.request); | ||
} | ||
return resp; | ||
} catch (err) { | ||
if (match) { | ||
lastOffline = Date.now(); | ||
console.log("Serving Anvil resources from Service Worker cache"); | ||
log && console.log("Offline cache hit:", e.request.url); | ||
return match; | ||
} else { | ||
log && console.log("Offline cache miss:", e.request.url); | ||
throw err; | ||
} | ||
} | ||
}; | ||
|
||
addEventListener('install', e => { | ||
console.log("Service Worker installed with scope:", registration.scope); | ||
}); | ||
|
||
addEventListener('activate', e => { | ||
e.waitUntil(cleanupOldCaches()); | ||
}); | ||
|
||
addEventListener('fetch', e => { | ||
e.respondWith(_fetch(e)) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
FROM ubuntu:18.04 | ||
FROM python:3 | ||
|
||
# This replicates a bug in OpenJDK 11. If you install openjdk-8-jdk, it will work | ||
RUN apt-get -yyy update && apt-get -yyy install openjdk-11-jdk python python-pip | ||
RUN apt-get -yyy update && apt-get -yyy install software-properties-common && \ | ||
wget -O- https://apt.corretto.aws/corretto.key | apt-key add - && \ | ||
add-apt-repository 'deb https://apt.corretto.aws stable main' | ||
|
||
COPY python-package-build /anvil-app-server-bin | ||
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \ | ||
(dpkg -i google-chrome-stable_current_amd64.deb || apt install -y --fix-broken) && \ | ||
rm google-chrome-stable_current_amd64.deb | ||
|
||
RUN pip install /anvil-app-server-bin | ||
|
||
VOLUME /apps | ||
RUN apt-get -yyy update && apt-get -yyy install java-1.8.0-amazon-corretto-jdk ghostscript | ||
|
||
RUN pip install anvil-app-server | ||
RUN anvil-app-server || true | ||
|
||
VOLUME /apps | ||
WORKDIR /apps | ||
|
||
ENV APP=MainApplication | ||
RUN mkdir /anvil-data | ||
|
||
RUN useradd anvil | ||
|
||
RUN chown -R anvil:anvil /anvil-data | ||
USER anvil | ||
|
||
CMD ["bash", "-c", "anvil-app-server --app $APP"] | ||
ENTRYPOINT ["anvil-app-server", "--data-dir", "/anvil-data"] | ||
|
||
# To run: | ||
# mkdir ~/tmp/anvil-apps/.anvil-data | ||
# chown -R 1000 ~/tmp/anvil-apps/.anvil-data | ||
# docker run --rm -v ~/tmp/anvil-apps:/apps -e APP=Feedbackform container-name | ||
CMD ["--app", "MainApp"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This code is based on the 'blank' template from the Anvil App Server. The template code is licensed under the following terms: | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This code is based on the 'hello-world' template from the Anvil App Server. The template code is licensed under the following terms: | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This code is based on the 'todo-list' template from the Anvil App Server. The template code is licensed under the following terms: | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.