Skip to content
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

[Feat] Removing Axios for Native Fetch #1278

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ca76896
remove axios package
sapiderman Mar 15, 2024
c57e074
Merge branch 'main' into feat/1248-remove-axios
sapiderman Apr 1, 2024
7ff1074
Merge branch 'main' into feat/1248-remove-axios
sapiderman Apr 17, 2024
c9951f5
remove send http via axios
sapiderman Apr 19, 2024
3489c54
convert insomnia
sapiderman Apr 30, 2024
54072f4
update symon worker to use fetch
sapiderman May 3, 2024
ed87495
update symon module
sapiderman May 10, 2024
5ee4caf
Merge branch 'main' into feat/1248-remove-axios
sapiderman May 10, 2024
db981d7
fix conflict
sapiderman May 10, 2024
0834377
Merge branch 'main' into feat/1248-remove-axios
sapiderman May 13, 2024
e46e6a2
fix prometheus test
sapiderman May 15, 2024
7ac9cfa
add insomnia unit test
sapiderman May 17, 2024
80ec4fe
Merge branch 'main' into feat/1248-remove-axios
sapiderman May 17, 2024
91dbaf0
fix config file return
sapiderman May 21, 2024
ccd9b41
add handler for json config files
sapiderman May 31, 2024
d6c1095
cleanup console.logs
sapiderman May 31, 2024
cd400a1
fix symon mode tests
sapiderman Jun 22, 2024
775de38
feat(http prober): #1285 implement cache http response (#1296)
syamsudotdev Jun 11, 2024
c1d30f1
feat: disable cache by default (#1297)
haricnugraha Jun 21, 2024
83d7e41
Feat: Handle CERT_HAS_EXPIRED_ERROR (#1299)
dennypradipta Jun 21, 2024
4409fbc
convert insomnia
sapiderman Apr 30, 2024
92adfe5
update symon module
sapiderman May 10, 2024
a14a848
define apiversion
sapiderman Jun 23, 2024
269e0eb
Merge branch 'main' into feat/1248-remove-axios
sapiderman Jul 8, 2024
e37a55b
tweak insomnia test
sapiderman Jul 11, 2024
6d2fac3
add explicit follow redir
sapiderman Jul 12, 2024
67482fa
remove .only
sapiderman Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"@sendgrid/mail": "^7.4.2",
"@types/pg": "^8.10.9",
"ajv": "^8.11.0",
"axios": "^0.27.2",
"boxen": "^5.0.0",
"chalk": "^4.1.2",
"chokidar": "^3.5.1",
Expand Down
7 changes: 4 additions & 3 deletions src/components/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { Config, ValidatedConfig } from '../../interfaces/config'
import { getContext, setContext } from '../../context'
import type { MonikaFlags } from '../../flag'
import { getEventEmitter } from '../../utils/events'
import { sendHttpRequest } from '../..//utils/http'
import { sendHttpRequestFetch } from '../../utils/http'
import { log } from '../../utils/pino'
import { getRawConfig } from './get'
import { getProbes, setProbes } from './probe'
Expand Down Expand Up @@ -61,8 +61,9 @@ async function createExampleConfigFile() {
'https://raw.githubusercontent.com/hyperjumptech/monika/main/monika.example.yml'

try {
const resp = await sendHttpRequest({ url })
await writeFile(outputFilePath, resp.data, { encoding: 'utf8' })
const resp = await sendHttpRequestFetch({ url })
const temp = await resp.text()
await writeFile(outputFilePath, temp, { encoding: 'utf8' })
} catch {
const ymlConfig = `
probes:
Expand Down
19 changes: 8 additions & 11 deletions src/components/config/parser/insomnia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import type { Config } from '../../../interfaces/config'
import yml from 'js-yaml'
import { compile as compileTemplate } from 'handlebars'
import type { AxiosRequestHeaders, Method } from 'axios'
import Joi from 'joi'

const envValidator = Joi.object({
Expand Down Expand Up @@ -140,20 +139,18 @@ function mapInsomniaToConfig(data: unknown): Config {
return { probes }
}

function mapInsomniaRequestToConfig(req: unknown) {
export function mapInsomniaRequestToConfig(req: unknown) {
const { value: res } = resourceValidator.validate(req, { allowUnknown: true })
// eslint-disable-next-line camelcase
const url = compileTemplate(res.url)({ base_url: baseUrl })
const authorization = getAuthorizationHeader(res)
let headers: AxiosRequestHeaders | undefined
if (authorization)
headers = {
authorization,
}

let headers: Headers | undefined
if (authorization) headers = new Headers({ Authorization: authorization })
if (res.headers) {
if (headers === undefined) headers = {}
if (headers === undefined) headers = new Headers()
for (const h of res.headers) {
headers[h.name] = h.value
headers.append(h.name, h.value)
}
}

Expand All @@ -164,7 +161,7 @@ function mapInsomniaRequestToConfig(req: unknown) {
requests: [
{
url,
method: (res?.method ?? 'GET') as Method,
method: res?.method ?? 'GET',
body: JSON.parse(res.body?.text ?? '{}'),
timeout: 10_000,
headers,
Expand All @@ -175,7 +172,7 @@ function mapInsomniaRequestToConfig(req: unknown) {
}
}

function getAuthorizationHeader(data: unknown): string | undefined {
export function getAuthorizationHeader(data: unknown): string | undefined {
const { value: res } = resourceValidator.validate(data, {
allowUnknown: true,
})
Expand Down
11 changes: 8 additions & 3 deletions src/components/config/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import isUrl from 'is-url'
import yml from 'js-yaml'

import type { Config } from '../../../interfaces/config'
import { sendHttpRequest } from '../../../utils/http'
import { sendHttpRequestFetch } from '../../../utils/http'
import { parseHarFile } from './har'
import { parseInsomnia } from './insomnia'
import { parseConfigFromPostman } from './postman'
Expand Down Expand Up @@ -85,10 +85,15 @@ async function getConfigFileFromUrl(url: string) {
return config
}

async function fetchConfigFile(url: string) {
async function fetchConfigFile(url: string): Promise<string> {
try {
const { data } = await sendHttpRequest({ url })
const resp = await sendHttpRequestFetch({ url, method: 'GET' })

if (!resp.ok) {
throw new Error(`The configuration file in ${url} is unreachable.`)
}

const data = await resp.text()
return data
} catch {
throw new Error(`The configuration file in ${url} is unreachable.`)
Expand Down
Loading
Loading