Skip to content

Commit 8073f79

Browse files
committed
Suppression des références au "site.ts" dans Vercel.
1 parent ea14c4d commit 8073f79

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

vercel/api/post-comment.js renamed to vercel/api/post-comment.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// noinspection ES6PreferShortImport
22

3+
import type { VercelRequest, VercelResponse } from '@vercel/node'
34
import { Octokit } from '@octokit/core'
45
import { v4 as uuidv4 } from 'uuid'
56
import * as yaml from 'yaml'
67
import { createAppAuth } from '@octokit/auth-app'
78
import { AkismetClient } from 'akismet-api'
89
import { createPullRequest } from 'octokit-plugin-create-pull-request'
9-
import { site } from '../../site/site'
10+
import type { Comment } from '../../types'
1011

11-
export default async function handler (request, response) {
12+
export default async function handler (request: VercelRequest, response: VercelResponse) {
1213
if (!allowCors(request, response)) {
1314
return
1415
}
@@ -22,7 +23,7 @@ export default async function handler (request, response) {
2223
}
2324

2425
const id = uuidv4()
25-
const comment = {
26+
const comment: Comment = {
2627
_id: id,
2728
level: request.body.level,
2829
lesson: request.body.lesson,
@@ -52,8 +53,8 @@ export default async function handler (request, response) {
5253

5354
const title = `Nouveau commentaire par ${comment.author} (${id})`
5455
const githubResponse = await octokit.createPullRequest({
55-
owner: site.github.username,
56-
repo: site.github.repository,
56+
owner: 'Skyost', // TODO: Use "site".
57+
repo: 'Bacomathiques',
5758
title,
5859
body: `Nouveau commentaire sur Bacomathiques !
5960
@@ -92,9 +93,9 @@ export default async function handler (request, response) {
9293
})
9394
}
9495

95-
function allowCors (request, response) {
96+
function allowCors (request: VercelRequest, response: VercelResponse) {
9697
response.setHeader('Access-Control-Allow-Credentials', 'true')
97-
response.setHeader('Access-Control-Allow-Origin', site.host)
98+
response.setHeader('Access-Control-Allow-Origin', 'https://bacomathiqu.es') // TODO: Same here.
9899
// response.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000')
99100
response.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT')
100101
response.setHeader(
@@ -108,7 +109,7 @@ function allowCors (request, response) {
108109
return true
109110
}
110111

111-
async function akismetSpam (request, comment) {
112+
async function akismetSpam (request: VercelRequest, comment: Comment) {
112113
if (!process.env.ASKIMET_API_KEY) {
113114
return true
114115
}
@@ -119,7 +120,7 @@ async function akismetSpam (request, comment) {
119120
})
120121

121122
return await client.checkSpam({
122-
ip: request.headers['x-forwarded-for'].toString(),
123+
ip: request.headers['x-forwarded-for']!.toString(),
123124
useragent: request.headers['user-agent'],
124125
content: comment.message,
125126
name: comment.author,

vercel/api/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"skipLibCheck": true,
6+
7+
/* Bundler mode */
8+
"moduleResolution": "node",
9+
"resolveJsonModule": true,
10+
"isolatedModules": true,
11+
"noEmit": true,
12+
13+
/* Linting */
14+
"strict": true,
15+
"noUnusedLocals": true,
16+
"noUnusedParameters": true,
17+
"noFallthroughCasesInSwitch": true
18+
}
19+
}

0 commit comments

Comments
 (0)