feat: 百度统计,处理vite代理后ip查询不可用问题
This commit is contained in:
+8
-2
@@ -1,6 +1,12 @@
|
||||
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
|
||||
NODE_ENV = 'dev'
|
||||
# 网站名称
|
||||
VITE_APP_TITLE = '工具坊'
|
||||
# 网站域名
|
||||
VITE_APP_WEBSITE = 'xxx.xxx.com'
|
||||
VITE_APP_BASE_API = '/api'
|
||||
VITE_SERVE = ''
|
||||
# base api
|
||||
VITE_APP_BASE_API = '/v1'
|
||||
# 服务端地址: https://xxx.xxx.com
|
||||
VITE_SERVE = ''
|
||||
# 是否使用mock: bool
|
||||
VITE_IS_MOCK = 'true'
|
||||
@@ -1,8 +1,6 @@
|
||||
<!-- vue3, vite, typescript, tailwindcss, pinia,vue-router, element-plus, pnpm -->
|
||||
<!-- codemirror -->
|
||||
# 工具站
|
||||
|
||||
当前包含工具:
|
||||
包含工具:
|
||||
- 时间戳转换
|
||||
- MD5在线加密
|
||||
- Json在线转换
|
||||
|
||||
+11
@@ -5,9 +5,20 @@
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title><%= title %></title>
|
||||
<!-- 百度统计 -->
|
||||
<script>
|
||||
var _hmt = _hmt || [];
|
||||
(function() {
|
||||
var hm = document.createElement("script");
|
||||
hm.src = "https://hm.baidu.com/hm.js?a94ed52bb5ed2bd9fdbad5b7468a9338";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
+10
-14
@@ -3,8 +3,8 @@ function getTools() {
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
value: '时间戳转换',
|
||||
img: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
title: '时间戳转换',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: '在线时间戳转换工具以及获取当前时间戳',
|
||||
url: '/timetran',
|
||||
cateId: 2,
|
||||
@@ -12,7 +12,7 @@ function getTools() {
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: 'MD5在线加密',
|
||||
title: 'MD5在线加密',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: 'MD5在线加密,长度包含32位、16位',
|
||||
url: '/MD5',
|
||||
@@ -21,7 +21,7 @@ function getTools() {
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: 'Json在线转换',
|
||||
title: 'Json在线转换',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: '在线编辑json, 语法检查',
|
||||
url: '/json',
|
||||
@@ -30,7 +30,7 @@ function getTools() {
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: '正则测试工具',
|
||||
title: '正则测试工具',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: '正则表达式测试工具, 常用正则表达式',
|
||||
url: '/reg',
|
||||
@@ -39,7 +39,7 @@ function getTools() {
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: 'Unicode转中文',
|
||||
title: 'Unicode转中文',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: 'Unicode和中文的相互转换',
|
||||
url: '/unicode',
|
||||
@@ -48,7 +48,7 @@ function getTools() {
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: '字数统计',
|
||||
title: '字数统计',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: '在线统计字符串的字数、段落、标点符号数量',
|
||||
url: '/wordCount',
|
||||
@@ -57,7 +57,7 @@ function getTools() {
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: 'IP查询',
|
||||
title: 'IP查询',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: '在线查询ip地址、ip归属地',
|
||||
url: '/ip',
|
||||
@@ -66,7 +66,7 @@ function getTools() {
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: '常用进制转换',
|
||||
title: '常用进制转换',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: '在线进制转换工具,可在2到64进制之间相互转换',
|
||||
url: '/scaletran',
|
||||
@@ -75,7 +75,7 @@ function getTools() {
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: '在线图片处理',
|
||||
title: '在线图片处理',
|
||||
logo: 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
|
||||
desc: '在线图片裁剪,标注,滤镜,画等操作',
|
||||
url: '/signimage',
|
||||
@@ -88,10 +88,6 @@ function getTools() {
|
||||
//获取tools分类
|
||||
function getToolsCate() {
|
||||
return [
|
||||
{
|
||||
id: 0,
|
||||
title: '全部工具',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: '开发运维'
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import type {
|
||||
|
||||
enum API {
|
||||
//获取ip
|
||||
GET_IP = '/v1/ip/get?ip='
|
||||
GET_IP = '/ip/get?ip='
|
||||
}
|
||||
//获取ip
|
||||
export const getIp = (ip:string) => request.get<any, getIpResponseData>(API.GET_IP + ip)
|
||||
@@ -16,6 +16,7 @@ const router = createRouter({
|
||||
})
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.meta.title && to.meta.title != '') {
|
||||
console.log(from)
|
||||
let oldTitle = document.title
|
||||
document.title = <string>to.meta.title + ' - ' + oldTitle
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ import axios from "axios";
|
||||
import { ElMessage } from "element-plus";
|
||||
//创建axios实例
|
||||
let request = axios.create({
|
||||
//判断mock是否启用
|
||||
baseURL: import.meta.env.VITE_IS_MOCK == 'true' ? import.meta.env.VITE_APP_BASE_API : import.meta.env.VITE_SERVE + import.meta.env.VITE_APP_BASE_API,
|
||||
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||
timeout: 5000
|
||||
})
|
||||
//请求拦截器
|
||||
|
||||
+19
-5
@@ -37,13 +37,27 @@ export default defineConfig(({command, mode}) => {
|
||||
},
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
'/v1/ip': {
|
||||
target: 'https://searchplugin.csdn.net', //ip查询
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^/api': ''
|
||||
}
|
||||
}
|
||||
rewrite: (path) => path.replace(/^\/v1\/ip/, '/api/v1/ip'),
|
||||
// bypass(req, res, options) {
|
||||
// console.log(1111)
|
||||
// const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target) as string)?.href || ''
|
||||
// req.headers['x-req-proxyUrl'] = proxyUrl;
|
||||
// res.setHeader("x-res-proxyUrl", proxyUrl)
|
||||
// }
|
||||
},
|
||||
[env.VITE_APP_BASE_API] : {
|
||||
target: env.VITE_SERVE,
|
||||
changeOrigin: true,
|
||||
// bypass(req, res, options) {
|
||||
// const proxyUrl = new URL(options.rewrite(req.url) || '', (options.target) as string)?.href || ''
|
||||
// req.headers['x-req-proxyUrl'] = proxyUrl;
|
||||
// res.setHeader("x-res-proxyUrl", proxyUrl)
|
||||
// }
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user