Skip to content

Commit 9da053a

Browse files
authored
Webhook Changes (#54)
* Change to 204 response * Use typescript in-constructor properties * Build docs
1 parent a5db985 commit 9da053a

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

docs/Api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const api = new Topgg.Api('Your top.gg token')
3838
<a name="Api+postStats"></a>
3939

4040
### api.postStats(stats) ⇒ <code>BotStats</code>
41-
Post bot stats to Top.gg (Do not use if you supplied a client)
41+
Post bot stats to Top.gg
4242

4343
**Kind**: instance method of [<code>Api</code>](#Api)
4444
**Returns**: <code>BotStats</code> - Passed object

src/structs/Webhook.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ import { WebhookPayload } from '../typings'
2424
* // Authorization: webhookauth123
2525
*/
2626
export class Webhook {
27-
private auth: string
28-
2927
/**
3028
* Create a new webhook client instance
3129
* @param authorization Webhook authorization to verify requests
3230
*/
33-
constructor (authorization?: string) {
34-
this.auth = authorization
35-
}
31+
constructor (private authorization?: string) {}
3632

3733
private _formatIncoming (body): WebhookPayload {
3834
if (body?.query?.length > 0) body.query = qs.parse(body.query.substr(1))
@@ -41,7 +37,7 @@ export class Webhook {
4137

4238
private _parseRequest (req, res): Promise<WebhookPayload|false> {
4339
return new Promise(resolve => {
44-
if (this.auth && req.headers.authorization !== this.auth) return res.status(403).json({ error: 'Unauthorized' })
40+
if (this.authorization && req.headers.authorization !== this.authorization) return res.status(403).json({ error: 'Unauthorized' })
4541
// parse json
4642

4743
if (req.body) return resolve(this._formatIncoming(req.body))
@@ -72,7 +68,7 @@ export class Webhook {
7268
return async (req, res, next) => {
7369
const response = await this._parseRequest(req, res)
7470
if (!response) return
75-
res.sendStatus(200)
71+
res.sendStatus(204)
7672
req.vote = response
7773
next()
7874
}

0 commit comments

Comments
 (0)