MCPcopy Index your code
hub / github.com/dev-mastery/comments-api / makePostComment

Function makePostComment

src/controllers/post-comment.js:1–37  ·  view source on GitHub ↗
({ addComment })

Source from the content-addressed store, hash-verified

1export default function makePostComment ({ addComment }) {
2 return async function postComment (httpRequest) {
3 try {
4 const { source = {}, ...commentInfo } = httpRequest.body
5 source.ip = httpRequest.ip
6 source.browser = httpRequest.headers['User-Agent']
7 if (httpRequest.headers['Referer']) {
8 source.referrer = httpRequest.headers['Referer']
9 }
10 const posted = await addComment({
11 ...commentInfo,
12 source
13 })
14 return {
15 headers: {
16 'Content-Type': 'application/json',
17 'Last-Modified': new Date(posted.modifiedOn).toUTCString()
18 },
19 statusCode: 201,
20 body: { posted }
21 }
22 } catch (e) {
23 // TODO: Error logging
24 console.log(e)
25
26 return {
27 headers: {
28 'Content-Type': 'application/json'
29 },
30 statusCode: 400,
31 body: {
32 error: e.message
33 }
34 }
35 }
36 }
37}

Callers 2

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected