Update to Koa 2

This commit is contained in:
Jonathan Cremin 2018-04-13 21:44:31 +01:00
parent 42b6cd5a32
commit 87459b2acc
15 changed files with 467 additions and 419 deletions

View file

@ -17,20 +17,18 @@ const recentQuery = {
],
};
export default function* () {
const recentAlbums = yield models.album.findAll(recentQuery);
const recentTracks = yield models.track.findAll(recentQuery);
export default async function (ctx) {
const recentAlbums = await models.album.findAll(recentQuery);
const recentTracks = await models.track.findAll(recentQuery);
const initialState = {
recents: recentAlbums.map(album => album.toJSON())
const serviceList = services.map(service => service.id);
const recents = recentAlbums.map(album => album.toJSON())
.concat(recentTracks.map(track => track.toJSON()))
.sort((a, b) => a.createdAt < b.createdAt).slice(0, 9),
services: services.map(service => service.id),
};
.sort((a, b) => a.createdAt < b.createdAt).slice(0, 9);
const url = '/';
const html = yield render(url, initialState);
const html = await render(url, { manifest: ctx.manifest, services: serviceList, recents });
const head = {
title: 'Share Music',
@ -39,10 +37,8 @@ export default function* () {
share: false,
};
this.set('Cache-Control', 'no-cache');
yield this.render('index', {
initialState,
await ctx.render('index', {
initialState: { services: serviceList, recents },
head,
html,
});