Skip to content

Commit

Permalink
Merge pull request jason5ng32#154 from jason5ng32/dev
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
jason5ng32 authored Apr 8, 2024
2 parents 90299eb + c051521 commit 31d8841
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 161 deletions.
34 changes: 34 additions & 0 deletions api/configs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 验证环境变量是否存在,以进行前端功能的开启和关闭
export default (req, res) => {
// 限制请求方法
if (req.method !== 'GET') {
return res.status(405).json({ message: 'Method Not Allowed' });
}

// 限制只能从指定域名访问
const allowedDomains = ['localhost', ...(process.env.ALLOWED_DOMAINS || '').split(',')];
const referer = req.headers.referer;
if (referer) {
const domain = new URL(referer).hostname;
if (!allowedDomains.includes(domain)) {
return res.status(403).json({ error: 'Access denied' });
}
} else {
return res.status(403).json({ error: 'What are you doing?' });
}

const envConfigs = {
bingMap: process.env.BING_MAP_API_KEY,
ipInfo: process.env.IPINFO_API_TOKEN,
ipChecking: process.env.IPChecking_API_KEY,
keyCDN: process.env.KEYCDN_USER_AGENT,
originalSite: req.headers.referer && (new URL(req.headers.referer).hostname === 'ipcheck.ing' || new URL(req.headers.referer).hostname === 'www.ipcheck.ing'),
cloudFlare: process.env.CLOUDFLARE_API,
recaptcha: process.env.VITE_RECAPTCHA_SITE_KEY && process.env.RECAPTCHA_SECRET_KEY
};
let result = {};
for (const key in envConfigs) {
result[key] = !!envConfigs[key];
}
res.status(200).json(result);
};
7 changes: 0 additions & 7 deletions api/validate-map-key.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/validate-recaptcha-key.js

This file was deleted.

4 changes: 0 additions & 4 deletions api/validate-site.js

This file was deleted.

16 changes: 5 additions & 11 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@ import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import mapHandler from './api/map.js';
import validateMapKeyHandler from './api/validate-map-key.js';
import validateSite from './api/validate-site.js';
import ipinfoHandler from './api/ipinfo.js';
import ipapicomHandler from './api/ipapicom.js';
import keycdnHandler from './api/keycdn.js';
import ipCheckingHandler from './api/ipchecking.js';
import ipsbHandler from './api/ipsb.js';
import cfHander from './api/cfradar.js';
import recaptchaHandler from './api/recaptcha.js';
import validateRecaptchaKey from './api/validate-recaptcha-key.js';
import validateConfigs from './api/configs.js';

dotenv.config();

const app = express();
const port = process.env.PORT || 11966;

// 使用查询参数处理所有地图请求
// APIs
app.get('/api/map', mapHandler);

// 使用查询参数处理所有 IP 地址请求
app.get('/api/ipinfo', ipinfoHandler);
app.get('/api/ipapicom', ipapicomHandler);
app.get('/api/keycdn', keycdnHandler);
Expand All @@ -31,16 +27,14 @@ app.get('/api/ipsb', ipsbHandler);
app.get('/api/cfradar', cfHander);
app.get('/api/recaptcha', recaptchaHandler);

// 使用查询参数处理所有配置请求
app.get('/api/configs', validateConfigs);

// 设置静态文件服务
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(express.static(path.join(__dirname, './dist')));

// 一些判断
app.all('/api/validate-map-key', validateMapKeyHandler);
app.all('/api/validate-site', validateSite);
app.all('/api/validate-recaptcha-key', validateRecaptchaKey);


// 启动服务器
app.listen(port, () => {
Expand Down
20 changes: 7 additions & 13 deletions src/components/footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,20 @@

<div v-for="(item, idx) in version.content" :key="idx" class="pb-1 ">
<span v-if="item.type === 'add'" class="badge rounded-pill bg-success fw-normal ">{{ $t('changelog.add')
}}</span>
}}</span>
<span v-else-if="item.type === 'improve'" class="badge rounded-pill bg-info fw-normal">{{
$t('changelog.improve') }}</span>
<span v-else-if="item.type === 'fix'" class="badge rounded-pill bg-danger fw-normal">{{ $t('changelog.fix')
}}</span>
<span v-else-if="item.type === 'fix'" class="badge rounded-pill bg-danger fw-normal">{{
$t('changelog.fix')
}}</span>
<span class="mx-2">{{ item.change }}</span>
</div>
</div>
</div>
</div>
</div>

<div id="copyright" v-if="!siteValidate">
<div id="copyright" v-if="!configs.originalSite">
<p class="text-center fs-6 fw-light" style="opacity: 0.5;">
{{ $t('page.copyRightName') }} <a :href="$t('page.copyRightLink')" class="link-underline-light" target="_blank"
:class="[isDarkMode ? 'dark-mode link-light' : 'link-dark']">{{ $t('page.copyRightLinkName') }}</a>
Expand All @@ -122,19 +123,12 @@ export default {
const store = useStore();
const isDarkMode = computed(() => store.state.isDarkMode);
const isMobile = computed(() => store.state.isMobile);
const siteVal = computed(() => store.state.siteValidate);
const siteValidate = ref(true);
// 监控 siteVal 的变化
watch(siteVal, (newVal) => {
siteValidate.value = newVal;
});
const configs = computed(() => store.state.configs);
return {
isDarkMode,
isMobile,
siteValidate,
configs,
};
},
Expand Down
Loading

0 comments on commit 31d8841

Please sign in to comment.