Commit 8cf60829 by zhanghaozhe

proxy

parent 2f880304
import React, { PureComponent } from 'react';
import SearchHead from './searchHead'
import Tag from '@common/Tag/index.js'
import { api } from '@/utils'
import {config} from '@/utils'
console.log(config)
import { http, api } from '@/utils'
import './index.scss';
......@@ -18,7 +16,7 @@ class Search extends PureComponent {
}
async componentDidMount() {
const data = await api.get(`/search/search_hot_word`)
const data = await http.get(`${api['search-api']}/search_hot_word`)
console.log(data)
}
......
const config = require('./utils/proxy-config')
const proxy = require('http-proxy-middleware')
const target = 'http://fast-test.julyedu.com'
module.exports = function (app) {
/*
app.use(proxy(
'/api',
{
target: 'http://fast-test.julyedu.com',
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
})
)
*/
/*
app.use(proxy(
config.home.development,
{
target,
changeOrigin: true,
pathRewrite: {
'^/api': ''
}
})
)
*/
Object.keys(config).forEach(item => {
app.use(proxy(
config[item]['development'], {
......@@ -44,8 +16,3 @@ module.exports = function (app) {
))
})
};
\ No newline at end of file
function generateProxyConfig(config) {
}
import config from './proxy-config'
let apiConfig = {}
Object.keys(config).forEach(item => {
if(item !== 'proxy'){
apiConfig[item] = config[item][process.env.NODE_ENV]
}
})
export default apiConfig
\ No newline at end of file
import axios from "axios";
import qs from 'qs'
import config from './proxy-config'
// export const BASE_URL = process.env.NODE_ENV === 'development' ? '/api' : 'https://api.julyedu.com'
let api = {}
const instance = axios.create({
// baseURL: BASE_URL,
transformRequest: [
(data) => qs.stringify(data)
],
headers: {
HTTP_PLAT_FORM: 5,
HTTP_PLAT: 5
Object.keys(config).forEach(item => {
if(item !== 'proxy'){
api[item] = config[item][process.env.NODE_ENV]
}
})
export default instance
\ No newline at end of file
export default api
\ No newline at end of file
import axios from "axios";
import qs from 'qs'
const instance = axios.create({
transformRequest: [
(data) => qs.stringify(data)
],
headers: {
HTTP_PLAT_FORM: 5,
HTTP_PLAT: 5
}
})
export default instance
\ No newline at end of file
export { default as http } from './http'
export { default as api } from './api'
export {default as config} from './api-config'
// 计算时间相差fn(过去距离当前时间)
export const computingTime = (pastTime) => {
var currentTime = (new Date()).getTime(),
......
......@@ -5,8 +5,8 @@ const config = {
production: 'https://m.julyedu.com',
proxy: {}
},
search: {
development: '/search',
'search-api': {
development: '/search-api',
test: 'https://search.julyedu.com',
production: 'https://search.julyedu.com',
proxy: {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment