import { json } from '@sveltejs/kit';
import { mongoConnect } from '$lib/database/mongo.server';

import type { ArticleSummary } from '$lib/posts/types';

const length = 8; // Number of posts to return

export async function GET({ url }) {
	const db = await mongoConnect();
	const col = db.db('fredboniface').collection('posts');
	const res = await col.find().sort({ _id: -1 }).limit(2).toArray();
	return json(res);
}

// The CONTENT field should be ommitted from the DB response
