Skip to content

Commit

Permalink
Add LastAccessed field to the payload
Browse files Browse the repository at this point in the history
Signed-off-by: Daksh Chauhan <dak-x@outlook.com>
  • Loading branch information
dak-x committed Aug 7, 2021
1 parent 5218ad6 commit fdb70fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
50 changes: 29 additions & 21 deletions kilde/postToSoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@

var htmlString = document.getElementsByTagName("html")[0].innerHTML
var url = document.URL
console.log(url)
var today = new Date()

jsonData = {
"url": url,
"dom": htmlString,
"lastaccessed": today.toISOString()
}

console.log(jsonData)

// POST method implementation:
async function postData(url = '', data = {}) {
const response = await fetch(url, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
body: JSON.stringify(data)
});
return response.json();
}
postData('http://localhost:8080/indexHtml', { "url" : url, "dom": htmlString})
.then(data => {
console.log(data); // JSON data parsed by `data.json()` call
});

const response = await fetch(url, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrerPolicy: 'no-referrer',
body: JSON.stringify(data)
});
return response.json();
}


postData('http://localhost:8080/indexHTML', jsonData)
.then(data => {
console.log(data); // JSON data parsed by `data.json()` call
});
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
app := gin.Default()
app.GET("/search/:query", searchHandler)
app.POST("/document", documentHandler)
app.POST("/indexHtml", processHTML)
app.POST("/indexHTML", processHTML)
app.Run("0.0.0.0:8080")
}

Expand Down
5 changes: 3 additions & 2 deletions models/htmlDoc.go → models/htmlDocument.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package models
var IndexName = "myindex"

type HtmlDocument struct {
Url string `json:"url"`
Dom string `json:"dom"`
Url string `json:"url"`
Dom string `json:"dom"`
LastAccessed string `json:"lastaccessed"`
}

// Mapping
Expand Down

0 comments on commit fdb70fe

Please sign in to comment.