fix(route): 修复使用ofetch之后的nosec路由 (#15113)

This commit is contained in:
zcw159357 2024-04-05 19:19:42 +08:00 committed by GitHub
parent 42014ee78e
commit 5adcc66283
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import { Route } from '@/types';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
const baseUrl = 'https://nosec.org/home/ajaxindexdata';
@ -39,10 +40,10 @@ export const route: Route = {
};
async function handler(ctx) {
const csrfresponse = await got.get('https://nosec.org/home/index');
const $ = load(csrfresponse.data);
const csrfresponse = await ofetch.raw('https://nosec.org/home/index');
const $ = load(csrfresponse._data);
const token = $('meta[name="csrf-token"]').attr('content');
const cookies = csrfresponse.headers['set-cookie'].toString();
const cookies = csrfresponse.headers.getSetCookie().toString();
const xsrf_token = cookies.match(/XSRF-TOKEN=[^\s;]+/)[0];
const laravel_session = cookies.match(/laravel_session[^\s;]+/)[0];
@ -71,7 +72,7 @@ async function handler(ctx) {
cookie: `${xsrf_token};${laravel_session}`,
'X-CSRF-TOKEN': token,
},
data: formdata,
body: formdata,
});
const data = response.data.data.threatData.data;