import fs from 'fs';
import { json } from '@sveltejs/kit';
import { error } from '@sveltejs/kit';

export let GET;

if (process.env.NODE_ENV === 'development') {
	const jsonFolder = './db/stream_json/';

	GET = function ({ params }) {
		const filePath = jsonFolder + params.stream_id + ".json";
		if (fs.existsSync(filePath)) {
			const jsonString = fs.readFileSync(filePath, 'utf8');
			return json(jsonString);
		} else {
			throw error(404);
		}
	}
}
