-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
82 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Main | ||
|
||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
paths: | ||
- "lib/sh/**" | ||
- "lib/zsh/**" | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
release: | ||
name: Create release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v2 | ||
- name: Download releaseartifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: release-artifacts | ||
path: lib | ||
- name: Generate checksum | ||
uses: jmgilman/actions-generate-checksum@57c13a1f01a90b2a8bb449ec29bc23728b96c1cd | ||
with: | ||
patterns: | | ||
lib/zsh/init.zsh | ||
- name: Create release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: | | ||
lib/zsh/checksum.txt | ||
lib/zsh/init.zsh |
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,30 +1,27 @@ | ||
async function handleRequest(event) { | ||
const request = event.request; | ||
const cacheUrl = new URL(request.url); | ||
const cacheKey = new Request(cacheUrl.toString(), request); | ||
const cache = caches.default; | ||
export default { | ||
async fetch(request, env, context) { | ||
try { | ||
const cacheUrl = new URL(request.url); | ||
const cacheKey = new Request(cacheUrl.toString(), request); | ||
const cache = caches.default; | ||
|
||
let response = await cache.match(cacheKey); | ||
let response = await cache.match(cacheKey); | ||
|
||
if (!response) { | ||
console.log( | ||
`Response for request url: ${request.url} not present in cache. Fetching and caching request.` | ||
); | ||
response = await fetch(request); | ||
response = new Response(response.body, response); | ||
response.headers.append("Cache-Control", "s-maxage=360"); | ||
if (!response) { | ||
console.log( | ||
`Response for request url: ${request.url} not present in cache. Fetching and caching request.` | ||
); | ||
response = await fetch(request); | ||
response = new Response(response.body, response); | ||
response.headers.append("Cache-Control", "s-maxage=60"); | ||
|
||
event.waitUntil(cache.put(cacheKey, response.clone())); | ||
} else { | ||
console.log(`Cache hit for: ${request.url}.`); | ||
} | ||
return response; | ||
} | ||
|
||
addEventListener("fetch", (event) => { | ||
try { | ||
return event.respondWith(handleRequest(event)); | ||
} catch (e) { | ||
return event.respondWith(new Response("Error thrown " + e.message)); | ||
} | ||
}); | ||
context.waitUntil(cache.put(cacheKey, response.clone())); | ||
} else { | ||
console.log(`Cache hit for: ${request.url}.`); | ||
} | ||
return response; | ||
} catch (e) { | ||
return new Response("Error thrown " + e.message); | ||
} | ||
}, | ||
}; |
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