| 216 | }; |
| 217 | |
| 218 | export const jsonResponse = ( |
| 219 | response: ServerResponse, |
| 220 | httpCode: keyof typeof codes = 200, |
| 221 | json: unknown = {}, |
| 222 | allowNull = true, |
| 223 | ): void => { |
| 224 | const httpMessage = codes[httpCode]; |
| 225 | const CTTHeader = `${contentTypes.json}; charset=${encodings.utf8}`; |
| 226 | |
| 227 | if (!response.headersSent) { |
| 228 | response.writeHead(httpMessage.code, { 'Content-Type': CTTHeader }); |
| 229 | response.end(removeNullStringify(json, allowNull)); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | return; |
| 234 | }; |
| 235 | |
| 236 | export const fetchJson = ( |
| 237 | url: string, |