-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api: Discourse API "proxy" endpoint at /api/comments #819
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
505077c
Add handle for getting comment count from Discourse
iAdramelk 0d4e8f1
Refactor api implementation in next.js style
iAdramelk a702fac
Remove unused cors field from server.js
iAdramelk 006a32d
Remove force-ssl-heroku form package.json
iAdramelk 99bfce2
Add url validation and origin to API handle
iAdramelk 2fd68dd
Update pages/api/comments.js
iAdramelk 6747a20
Update pages/api/comments.js
iAdramelk 1b395f9
Fix code styles
iAdramelk 2d3dbfd
Remove erro message for incorrect forum url in request
iAdramelk 64b0749
Upadte consts
iAdramelk 6b9d01a
Add comment to pages/api/comments.js
iAdramelk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This API endpoint is used by https://blog.dvc.org | ||
* to get comments count for the post, it gets | ||
* discuss.dvc.org topic url as a param and returns | ||
* comments count or error. | ||
* | ||
* It made this way to configure CORS, reduce user's payload | ||
* and to add potential ability to cache comments count | ||
* in the future. | ||
*/ | ||
|
||
import Cors from 'micro-cors' | ||
import request from 'request' | ||
|
||
import { BLOG_URL, FORUM_URL } from '../../src/consts' | ||
|
||
const cors = Cors({ | ||
shcheklein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
allowedMethods: ['GET', 'HEAD'], | ||
origin: BLOG_URL | ||
}) | ||
|
||
const getCommentCount = (req, res) => { | ||
const { | ||
query: { url } | ||
} = req | ||
|
||
if (!url.startsWith(FORUM_URL)) { | ||
res.status(400) | ||
|
||
return | ||
} | ||
|
||
request(`${url}.json`, (error, response, body) => { | ||
if (error || response.statusCode !== 200) { | ||
res.status(502).json({ error: 'Unexpected response from Forum' }) | ||
|
||
return | ||
} | ||
|
||
const json = JSON.parse(body) | ||
|
||
if (!json.posts_count) { | ||
res.status(502).json({ error: 'Unexpected payload from Forum' }) | ||
|
||
return | ||
} | ||
|
||
// post_count return all posts including topic itself | ||
const count = json.posts_count - 1 | ||
|
||
res.status(200).json({ count }) | ||
}) | ||
} | ||
|
||
export default cors(getCommentCount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
export const HEADER = 'header' | ||
|
||
const WEBSITE_HOST = 'dvc.org' | ||
|
||
export const META_BASE_TITLE = 'Data Version Control · DVC' | ||
export const META_DESCRIPTION = | ||
'Open-source version control system for Data Science and Machine Learning ' + | ||
'projects. Git-like experience to organize your data, models, and ' + | ||
'experiments.' | ||
export const META_KEYWORDS = | ||
'data version control machine learning models management' | ||
export const META_SOCIAL_IMAGE = 'https://dvc.org/static/social-share.png' | ||
export const META_SOCIAL_IMAGE = `https://${WEBSITE_HOST}/static/social-share.png` | ||
|
||
export const FORUM_URL = `https://discuss.${WEBSITE_HOST}` | ||
export const BLOG_URL = `https://blog.${WEBSITE_HOST}` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rewrap this.