move purify to server side.

This commit is contained in:
Jason Schwarzenberger
2020-12-02 15:46:06 +13:00
parent cee104ea06
commit d1c513b9d6
11 changed files with 639 additions and 30 deletions

View File

@@ -1,5 +1,7 @@
import fetch from 'isomorphic-fetch';
import { purifyArray } from './_purify';
const API_URL = process.env.API_URL || 'http://localhost:33842';
export async function get(req, res) {
@@ -9,5 +11,10 @@ export async function get(req, res) {
};
const response = await fetch(`${API_URL}/api?skip=${skip}&limit=${limit}`);
res.writeHead(response.status, { 'Content-Type': 'application/json' });
res.end(await response.text());
if (!response.ok) {
return res.end(await response.text());
}
const data = await response.json();
data.stories = purifyArray(data.stories);
res.end(JSON.stringify(data));
}