Skip to content

Commit

Permalink
chore(page): relocate initial data fetch to router
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch committed Sep 28, 2024
1 parent 6f55090 commit 31c004a
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 37 deletions.
10 changes: 5 additions & 5 deletions apps/page/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';
// import node from '@astrojs/node';
import node from '@astrojs/node';
import vue from '@astrojs/vue';

import tailwind from '@astrojs/tailwind';

// https://astro.build/config
export default defineConfig({
output: 'server',
// adapter: node({
// mode: 'standalone'
// }),
adapter: cloudflare(),
adapter: node({
mode: 'standalone'
}),
// adapter: cloudflare(),
integrations: [vue({ appEntrypoint: '/src/app' }), tailwind()]
});
5 changes: 3 additions & 2 deletions apps/page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "0.0.1",
"scripts": {
"serve": "astro dev",
"serve": "astro dev --inspect",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro"
Expand All @@ -18,12 +18,13 @@
"@podlove/clients": "workspace:*",
"@podlove/webvtt-parser": "workspace:*",
"@astrojs/check": "0.9.3",
"@astrojs/node": "8.3.4",
"@astrojs/tailwind": "5.1.1",
"@astrojs/vue": "4.5.1",
"@astrojs/cloudflare": "11.1.0",
"astro": "4.15.9",
"vue": "3.5.10",
"fast-xml-parser": "4.3.2",
"fast-xml-parser": "4.5.0",
"lodash-es": "4.17.21",
"redux": "4.2.1",
"redux-vuex": "3.1.2",
Expand Down
2 changes: 0 additions & 2 deletions apps/page/src/logic/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { stepperSaga } from '@podlove/player-sagas/stepper';
import { lifeCycleSaga } from '@podlove/player-sagas/lifecycle';

import { selectors } from '../store';
import dataSagas from './data.sagas';
import episodeSagas from './episode.sagas';
import playbarSagas from './playbar.sagas';
import routerSaga from './router.sagas';
Expand All @@ -19,7 +18,6 @@ export async function createSideEffects() {
const sagas = [
lifeCycleSaga,
routerSaga,
dataSagas({ selectInitializedApp: selectors.runtime.initialized }),
episodeSagas({
selectEpisode: selectors.episode.data,
selectShow: selectors.podcast.show,
Expand Down
15 changes: 8 additions & 7 deletions apps/page/src/middleware/store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { defineMiddleware } from 'astro:middleware';
import { waitFor } from '@podlove/utils/promise';
import { toInteger } from 'lodash-es';
import { actions, store, selectors } from '../logic';
import { getRequestHeader } from '../lib/middleware';
import parseFeed from '../logic/data/feed-parser';
import type { Podcast } from '../types/feed.types';
import { createHash } from '../lib/caching';
import { version } from '../../package.json';

export const initializeStore = defineMiddleware(async ({ request, params }, next) => {
const locale = getRequestHeader(request, 'accept-language', 'en-US');
Expand All @@ -14,12 +17,10 @@ export const initializeStore = defineMiddleware(async ({ request, params }, next

store.dispatch(actions.lifecycle.initializeApp({ feed, locale, episodeId: toInteger(episodeId) }));

await waitFor(() => {
const initialized = selectors.runtime.initialized(store.getState());
return initialized ? true : undefined;
}, 10000).catch(() => {
throw Error('Request timed out');
});
const data: Podcast = await parseFeed({ feed, episodeId: toInteger(episodeId) });
const cacheKey: string | null = data.etag ? await createHash(`${data.etag}${version}`) : null;

store.dispatch(actions.lifecycle.dataFetched({ data, cacheKey }));

return next();
});
Loading

0 comments on commit 31c004a

Please sign in to comment.