From e53bddfc71d70eb9f2b7a2910b4b191bc43088ab Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Tue, 13 Oct 2020 20:28:52 +0200 Subject: First commit --- src/client.ts | 4 + src/components/Nav.svelte | 60 +++++++ src/components/PredictedSpaceWeather.svelte | 174 +++++++++++++++++++ src/components/PredictedSpaceWeatherThing.svelte | 64 +++++++ src/components/WeatherCurrent.svelte | 210 +++++++++++++++++++++++ src/routes/_error.svelte | 40 +++++ src/routes/_layout.svelte | 54 ++++++ src/routes/index.svelte | 28 +++ src/server.ts | 18 ++ src/service-worker.ts | 82 +++++++++ src/template.html | 35 ++++ 11 files changed, 769 insertions(+) create mode 100644 src/client.ts create mode 100644 src/components/Nav.svelte create mode 100644 src/components/PredictedSpaceWeather.svelte create mode 100644 src/components/PredictedSpaceWeatherThing.svelte create mode 100644 src/components/WeatherCurrent.svelte create mode 100644 src/routes/_error.svelte create mode 100644 src/routes/_layout.svelte create mode 100644 src/routes/index.svelte create mode 100644 src/server.ts create mode 100644 src/service-worker.ts create mode 100644 src/template.html (limited to 'src') diff --git a/src/client.ts b/src/client.ts new file mode 100644 index 0000000..1a2fbc3 --- /dev/null +++ b/src/client.ts @@ -0,0 +1,4 @@ +import * as sapper from '@sapper/app'; +sapper.start({ + target: document.querySelector('.app') +}); diff --git a/src/components/Nav.svelte b/src/components/Nav.svelte new file mode 100644 index 0000000..3240ecf --- /dev/null +++ b/src/components/Nav.svelte @@ -0,0 +1,60 @@ + + + + + diff --git a/src/components/PredictedSpaceWeather.svelte b/src/components/PredictedSpaceWeather.svelte new file mode 100644 index 0000000..9194447 --- /dev/null +++ b/src/components/PredictedSpaceWeather.svelte @@ -0,0 +1,174 @@ + + + + +
+
+

Predicted

+
+
+ {#if predictions} + {#each predictions as prediction, i} + + {/each} + {:else} + Cannot connect to NOAA + {/if} +
+
diff --git a/src/components/PredictedSpaceWeatherThing.svelte b/src/components/PredictedSpaceWeatherThing.svelte new file mode 100644 index 0000000..0a40e79 --- /dev/null +++ b/src/components/PredictedSpaceWeatherThing.svelte @@ -0,0 +1,64 @@ + + + + +
+
+

{time}

+

{date}

+
+
+

{kp}

+
+

{temp}°C

+

{clouds}%

+
+
+
diff --git a/src/components/WeatherCurrent.svelte b/src/components/WeatherCurrent.svelte new file mode 100644 index 0000000..6f92b20 --- /dev/null +++ b/src/components/WeatherCurrent.svelte @@ -0,0 +1,210 @@ + + + + +
+
+
+ +

{location}

+
+ +
+

{date}

+
+ +
+

KP {kp_now}

+

+ ↑ KP {kp_max} + ↓ KP {kp_min} +

+
+ +
+
+

BZ

+

{bz}

+
+
+

Probability

+

10%

+
+
+

Clouds

+

{clouds}%

+
+
+ +
+
diff --git a/src/routes/_error.svelte b/src/routes/_error.svelte new file mode 100644 index 0000000..92fcca8 --- /dev/null +++ b/src/routes/_error.svelte @@ -0,0 +1,40 @@ + + + + + + {status} + + +

{status}

+ +

{error.message}

+ +{#if dev && error.stack} +
{error.stack}
+{/if} diff --git a/src/routes/_layout.svelte b/src/routes/_layout.svelte new file mode 100644 index 0000000..bab4188 --- /dev/null +++ b/src/routes/_layout.svelte @@ -0,0 +1,54 @@ + + + + +
+ + + +
diff --git a/src/routes/index.svelte b/src/routes/index.svelte new file mode 100644 index 0000000..655f0c4 --- /dev/null +++ b/src/routes/index.svelte @@ -0,0 +1,28 @@ + + + + + + + Aurora data + + + +
+ + +
diff --git a/src/server.ts b/src/server.ts new file mode 100644 index 0000000..8425b2c --- /dev/null +++ b/src/server.ts @@ -0,0 +1,18 @@ +import sirv from 'sirv'; +import polka from 'polka'; +import compression from 'compression'; +import * as sapper from '@sapper/server'; + +const { PORT, NODE_ENV } = process.env; +const dev = NODE_ENV === 'development'; + +polka() // You can also use Express + .use( + 'aurora-data', + compression({ threshold: 0 }), + sirv('static', { dev }), + sapper.middleware() + ) + .listen(PORT, err => { + if (err) console.log('error', err); + }); diff --git a/src/service-worker.ts b/src/service-worker.ts new file mode 100644 index 0000000..1441676 --- /dev/null +++ b/src/service-worker.ts @@ -0,0 +1,82 @@ +import { timestamp, files, shell, routes } from '@sapper/service-worker'; + +const ASSETS = `cache${timestamp}`; + +// `shell` is an array of all the files generated by the bundler, +// `files` is an array of everything in the `static` directory +const to_cache = (shell as string[]).concat(files as string[]); +const cached = new Set(to_cache); + +self.addEventListener('install', (event: EventType) => { + event.waitUntil( + caches + .open(ASSETS) + .then(cache => cache.addAll(to_cache)) + .then(() => { + ((self as any) as ServiceWorkerGlobalScope).skipWaiting(); + }) + ); +}); + +self.addEventListener('activate', (event: EventType) => { + event.waitUntil( + caches.keys().then(async keys => { + // delete old caches + for (const key of keys) { + if (key !== ASSETS) await caches.delete(key); + } + + ((self as any) as ServiceWorkerGlobalScope).clients.claim(); + }) + ); +}); + +self.addEventListener('fetch', (event: EventType) => { + if (event.request.method !== 'GET' || event.request.headers.has('range')) return; + + const url = new URL(event.request.url); + + // don't try to handle e.g. data: URIs + if (!url.protocol.startsWith('http')) return; + + // ignore dev server requests + if (url.hostname === self.location.hostname && url.port !== self.location.port) return; + + // always serve static files and bundler-generated assets from cache + if (url.host === self.location.host && cached.has(url.pathname)) { + event.respondWith(caches.match(event.request)); + return; + } + + // for pages, you might want to serve a shell `service-worker-index.html` file, + // which Sapper has generated for you. It's not right for every + // app, but if it's right for yours then uncomment this section + /* + if (url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) { + event.respondWith(caches.match('/service-worker-index.html')); + return; + } + */ + + if (event.request.cache === 'only-if-cached') return; + + // for everything else, try the network first, falling back to + // cache if the user is offline. (If the pages never change, you + // might prefer a cache-first approach to a network-first one.) + event.respondWith( + caches + .open(`offline${timestamp}`) + .then(async cache => { + try { + const response = await fetch(event.request); + cache.put(event.request, response.clone()); + return response; + } catch(err) { + const response = await cache.match(event.request); + if (response) return response; + + throw err; + } + }) + ); +}); diff --git a/src/template.html b/src/template.html new file mode 100644 index 0000000..f7382aa --- /dev/null +++ b/src/template.html @@ -0,0 +1,35 @@ + + + + + + + + %sapper.base% + + + + + + + + %sapper.scripts% + + + %sapper.styles% + + + %sapper.head% + + +
+ %sapper.html% +
+ + + -- cgit v1.2.3