move purify to server side.
This commit is contained in:
@@ -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));
|
||||
}
|
Reference in New Issue
Block a user