Skip to content

Instantly share code, notes, and snippets.

View konstantinmuenster's full-sized avatar
🙌

Konstantin Münster konstantinmuenster

🙌
View GitHub Profile
@konstantinmuenster
konstantinmuenster / sw.fetch.js
Created January 24, 2020 15:23
Service Worker Rendering - Fetch Event
self.addEventListener('fetch', function(event) {
var requestURL = new URL(event.request.url);
if (/^\/post\//.test(requestURL.pathname)) {
event.respondWith(
Promise.all([
caches.match('/post/', {ignoreSearch: true}).then(function(response) {
return response.text();
}),
@konstantinmuenster
konstantinmuenster / gatsby-node.js
Created December 22, 2019 18:14
Example createRedirect for Netlify redirects
exports.createPages = ({ actions }) => {
const { createRedirect } = actions;
createRedirect({
fromPath: "https://yoursubdomain.netlify.com/*",
toPath: "https://www.yourcustomdomain.com/:splat",
isPermanent: true,
force: true
});
};
@konstantinmuenster
konstantinmuenster / _redirects
Last active December 23, 2019 11:19
Example Netlify Redirect
# Redirect default Netlify subdomain to primary domain
https://yoursubdomain.netlify.com/* https://www.yourcustomdomain.com/:splat 301!
@konstantinmuenster
konstantinmuenster / Understanding-Async-Await-2.js
Created September 19, 2019 09:39
Understanding Async/Await - Resolved Example
const fetchData = async (url) => {
try {
const response = await fetch(url);
const data = await response.json();
return data;
} catch(error) {
// Handle errors as needed
}
}
@konstantinmuenster
konstantinmuenster / Understanding-Async-Await.js
Last active September 19, 2019 19:13
Understanding Async/Await (Medium) - Example
const fetchData = async (url) => {
try {
const response = await fetch(url);
const data = await response.json();
return data;
} catch(error) {
// Handle errors as needed
}
}