mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Finish axios migration via shared native HTTP helper
Replace all in-scope axios callsites with a new helpers/http.js wrapper over native fetch, including JSON/text GET, JSON POST, HEAD checks, and transient 5xx retry behavior; update all browser, build, script, and proxy API clients to use it; add focused unit tests; and remove axios from package dependencies. Constraint: Preserve API/build and deployment behavior while lowering transport surface area. Rejected: inline fetch replacements at each callsite | rejected to avoid inconsistent error/retry semantics. Confidence: high Scope-risk: moderate Directive: Keep helper in place as the transport boundary and update tests when changing request semantics. Tested: pnpm run -s typecheck, pnpm -s run test-prebuild, pnpm -s run test, pnpm -s run test:browser, pnpm -s run netlify-build, smoke GETs on /apple-silicon-app-test and /apple-silicon-app-test/?version=2 Not-tested: branch/netlify deployment health in CI pipeline after merge
This commit is contained in:
parent
d39a2a1d6c
commit
d45b587434
25 changed files with 824 additions and 267 deletions
|
|
@ -12,9 +12,8 @@
|
|||
// GET /api/tiles/public/static/3/4/2.json?turn=37038&games=wot
|
||||
// DoesItAPI.tiles.public.static(3)(4)(`${2}.json`).get({ turn: 37, games: 'wot' })
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
import { getApiUrl } from '~/helpers/url.js'
|
||||
import { requestJson } from '~/helpers/http.js'
|
||||
|
||||
// Use msw
|
||||
import '~/test/msw/use.js'
|
||||
|
|
@ -22,8 +21,7 @@ import '~/test/msw/use.js'
|
|||
// const defaultFetchMethod = (...args) => console.log(...args) // mock
|
||||
|
||||
const defaultFetchMethod = async function (...args) {
|
||||
return axios(...args)
|
||||
.then( response => response.data )
|
||||
return requestJson(...args)
|
||||
.catch( error => {
|
||||
if ( error?.response?.status !== 404 ) {
|
||||
console.error( error )
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import path from 'path'
|
||||
import fs from 'fs-extra'
|
||||
import axios from 'axios'
|
||||
import { parse } from 'fast-xml-parser'
|
||||
|
||||
import {
|
||||
|
|
@ -8,6 +7,10 @@ import {
|
|||
sitemapIndexFileName,
|
||||
} from '~/helpers/constants.js'
|
||||
import { isValidHttpUrl } from '~/helpers/check-types.js'
|
||||
import {
|
||||
getText,
|
||||
headOk
|
||||
} from '~/helpers/http.js'
|
||||
|
||||
const sitemapFilesToTry = [
|
||||
sitemapIndexFileName,
|
||||
|
|
@ -106,12 +109,7 @@ export async function fetchAllUrlsFromSitemaps ( urlString ) {
|
|||
// console.log( 'sitemapUrl', sitemapUrl.href )
|
||||
|
||||
// Just do a quich HEAD request to see if the file exists with getting the whole body
|
||||
const exists = await axios.head( sitemapUrl.href )
|
||||
.catch( () => false )
|
||||
.then( response => {
|
||||
// console.log( 'response', response.status )
|
||||
return response.status < 300
|
||||
} )
|
||||
const exists = await headOk( sitemapUrl.href )
|
||||
|
||||
// console.log( 'exists', exists )
|
||||
|
||||
|
|
@ -123,8 +121,7 @@ export async function fetchAllUrlsFromSitemaps ( urlString ) {
|
|||
getMethod: async sitemapPath => {
|
||||
const sitemapUrl = new URL( sitemapPath, urlString )
|
||||
|
||||
const sitemapXml = await axios.get( sitemapUrl.href )
|
||||
.then( response => response.data )
|
||||
const sitemapXml = await getText( sitemapUrl.href )
|
||||
|
||||
return sitemapXml
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import fs from 'fs-extra'
|
||||
import axios from 'axios'
|
||||
import 'dotenv/config.js'
|
||||
|
||||
import {
|
||||
|
|
@ -8,6 +7,7 @@ import {
|
|||
// storkExecutablePath,
|
||||
storkTomlPath,
|
||||
} from '~/helpers/stork/config.js'
|
||||
import { getText } from '~/helpers/http.js'
|
||||
|
||||
export async function downloadStorkToml () {
|
||||
// Check if the toml file exists
|
||||
|
|
@ -20,12 +20,9 @@ export async function downloadStorkToml () {
|
|||
|
||||
apiUrl.pathname = storkTomlPath.replace('static/', '')
|
||||
|
||||
const response = await axios({
|
||||
method: "get",
|
||||
url: apiUrl.toString(),
|
||||
})
|
||||
const storkToml = await getText( apiUrl.toString() )
|
||||
|
||||
await fs.writeFile( storkTomlPath, response.data, { encoding: null })
|
||||
await fs.writeFile( storkTomlPath, storkToml, { encoding: null })
|
||||
|
||||
// Get toml file stats
|
||||
const stats = await fs.stat( storkTomlPath )
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import fs from 'fs-extra'
|
||||
import { google } from 'googleapis'
|
||||
import axios from 'axios'
|
||||
|
||||
import { playlists, benchmarksPlaylistId } from './playlists.js'
|
||||
import { getJson } from '~/helpers/http.js'
|
||||
|
||||
|
||||
export const youtubeVideoPath = './static/api/youtube-videos.json'
|
||||
|
|
@ -167,8 +167,7 @@ export async function saveYouTubeVideos () {
|
|||
// const youtubeVideos = await getYouTubeVideos()
|
||||
|
||||
// Locked previously sucessful YouTube API data for now
|
||||
const youtubeVideos = await axios( process.env.VIDEO_SOURCE )
|
||||
.then( response => response.data )
|
||||
const youtubeVideos = await getJson( process.env.VIDEO_SOURCE )
|
||||
|
||||
|
||||
// Save to JSON
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue