Skip to content

Commit

Permalink
Merge pull request #10 from JoBinsJP/axios-setup
Browse files Browse the repository at this point in the history
feat: custom axios setup
  • Loading branch information
bedus-creation authored Mar 5, 2023
2 parents 3d644ac + fdde50d commit 2e3e043
Show file tree
Hide file tree
Showing 19 changed files with 3,942 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm publish --workspace=packages --if-present

##### Set version
```bash
npm version {version} --workspace=packages --if-present
npm version minor --workspace=packages --if-present
```

##### Test
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Run Tests - Current"

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
adapter: [ 'core','vue2' ]
node-version: [ 14.x ]
steps:
- uses: actions/checkout@v3
- name: Testing ${{ matrix.adapter }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: cd packages/${{ matrix.adapter }} && npm install && npm run build && npm run test
89 changes: 58 additions & 31 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formjs-core",
"version": "0.0.23",
"version": "0.0.30",
"type": "module",
"contributors": [
"Bedram Tamang <[email protected]>"
Expand All @@ -20,7 +20,7 @@
}
},
"scripts": {
"test": "vitest",
"test": "vitest run -r tests",
"build": "npm run clean && tsc --emitDeclarationOnly && vite build",
"clean": "rm -rf types && rm -rf dist",
"prepublishOnly": "npm run build"
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ export class Http {
forceFormData = false,
onFinish = () => {},
onSuccess = () => {},
onErrors = () => {},
onError = () => {},
instance = Axios,
}: VisitOptions = {},
): void {
const defaultBaseURL = Axios.defaults.baseURL
const authorizationToken = Axios.defaults.headers.common['Authorization']

let url = typeof href === "string" ? hrefToUrl(href, defaultBaseURL) : href

if ((hasFiles(data) || forceFormData) && !(data instanceof FormData)) {
data = objectToFormData(data)
}

Axios({
const defaultConfig = instance?.defaults
let url = typeof href === "string" ? hrefToUrl(href, defaultConfig?.baseURL) : href

const _url = urlWithoutHash(url).href

instance(_url, {
...defaultConfig,
method,
baseURL: defaultBaseURL,
url: urlWithoutHash(url).href,
data: method === "get" ? {} : data,
params: method === "get" ? data : {},
headers: {
Accept: "application/json",
Authorization: authorizationToken,
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest",
...headers,
Expand All @@ -49,10 +49,10 @@ export class Http {
Object.keys(responseErrors).forEach((name) => {
errors[name] = responseErrors[name][0]
})
return onError(errors)
return onErrors(errors)
}
}
return Promise.reject(error)
return onError(error)
}).then(() => {
return onFinish()
}).catch((error) => {
Expand Down
Loading

0 comments on commit 2e3e043

Please sign in to comment.