chore: set new env
This commit is contained in:
parent
3f896d3824
commit
c98e72d8d9
4
.env
4
.env
|
@ -1,2 +1,2 @@
|
|||
# NEXT_PUBLIC_BASE_URL=https://api-staging.cariparkir.co.id
|
||||
NEXT_PUBLIC_BASE_URL=https://ad09-101-255-119-166.ap.ngrok.io
|
||||
NEXT_PUBLIC_STAGING_CP_URL=https://api-staging.cariparkir.co.id
|
||||
NEXT_PUBLIC_BASE_URL=https://api-bookinglockey-staging.cariparkir.co.id
|
|
@ -1,3 +1,4 @@
|
|||
export const appConfig = {
|
||||
apiUrl: process.env.NEXT_PUBLIC_BASE_URL
|
||||
apiUrl: process.env.NEXT_PUBLIC_BASE_URL,
|
||||
apiCpUrl: process.env.NEXT_PUBLIC_STAGING_CP_URL,
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import {http} from "../utils/http";
|
||||
import { http2 } from "../utils/http2"
|
||||
|
||||
const url = {
|
||||
contacts: () => '/product/api/v5/customer-service'
|
||||
|
@ -8,7 +8,7 @@ const hooks = {}
|
|||
|
||||
const api = {
|
||||
async getContacts() {
|
||||
return await http.fetcher(url.contacts())
|
||||
return await http2.fetcher(url.contacts())
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
import {http} from "../utils/http";
|
||||
|
||||
const url = {
|
||||
payment: () => '/usermanagement/api/v5/validate/check-phone-register'
|
||||
payment: () => '/usermanagement/api/v5/validate/check-phone-register',
|
||||
sendInvoice: () => '/payment-service/api/v6/send-invoice',
|
||||
}
|
||||
|
||||
const hooks = {}
|
||||
|
||||
const api = {
|
||||
// async usePayment(data) {
|
||||
// return await http.post(url.payment, data)
|
||||
// },
|
||||
}
|
||||
const api = {}
|
||||
|
||||
export const orderRepository = {
|
||||
url,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {http} from "../utils/http";
|
||||
import { http } from "../utils/http";
|
||||
import { http2 } from "../utils/http2";
|
||||
import {botsRepository} from "../repository/bots";
|
||||
import { orderRepository } from "../repository/order";
|
||||
|
||||
|
@ -12,6 +13,6 @@ export class LockeyStore {
|
|||
}
|
||||
|
||||
createPayment(body) {
|
||||
return http.post(orderRepository.url.payment(), body);
|
||||
return http2.post(orderRepository.url.payment(), body);
|
||||
}
|
||||
}
|
||||
|
|
78
utils/http2.js
Normal file
78
utils/http2.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
import {appConfig} from "../config/app";
|
||||
import {TokenUtil} from "./token";
|
||||
import axios from "axios";
|
||||
|
||||
const instanceCp = axios.create({
|
||||
baseURL: appConfig.apiCpUrl,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
instanceCp.interceptors.request.use(
|
||||
(config) => {
|
||||
if (TokenUtil.accessToken) {
|
||||
config.headers["Authorization"] = 'Bearer ' + TokenUtil.accessToken; // for Node.js Express back-end
|
||||
}
|
||||
config.headers["ngrok-skip-browser-warning"] = true
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
instanceCp.interceptors.response.use(
|
||||
(res) => {
|
||||
return res;
|
||||
},
|
||||
async (err) => {
|
||||
const originalConfig = err.config;
|
||||
|
||||
if (originalConfig.url !== "/auth/login" && err.response) {
|
||||
// Access Token was expired
|
||||
if (err.response.status === 401 && !originalConfig._retry) {
|
||||
originalConfig._retry = true;
|
||||
|
||||
try {
|
||||
if (TokenUtil.refreshToken) {
|
||||
await authenticationRepository.api.refreshToken()
|
||||
}
|
||||
return instanceCp(originalConfig);
|
||||
} catch (_error) {
|
||||
return Promise.reject(_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.reject(err);
|
||||
}
|
||||
);
|
||||
|
||||
export const http2 = {
|
||||
fetcher: async (url) => {
|
||||
const resp = await instanceCp.get(appConfig.apiCpUrl + url);
|
||||
|
||||
return resp.data;
|
||||
},
|
||||
get: async (url, opts = {}) => {
|
||||
const resp = await instanceCp.post(appConfig.apiCpUrl + url);
|
||||
|
||||
return resp.data;
|
||||
},
|
||||
post: async (url, data, opts) => {
|
||||
const resp = await instanceCp.post(appConfig.apiCpUrl + url, data);
|
||||
|
||||
return resp.data;
|
||||
},
|
||||
put: async (url, data, opts) => {
|
||||
const resp = await instanceCp.put(appConfig.apiCpUrl + url, data);
|
||||
|
||||
return resp.data;
|
||||
},
|
||||
del: async (url, opts) => {
|
||||
const resp = await instanceCp.delete(appConfig.apiCpUrl + url);
|
||||
|
||||
return resp.data;
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue
Block a user