Skip to content

Commit

Permalink
添加用于测速的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
xfgryujk committed Nov 12, 2024
1 parent fb9e041 commit de3712a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
CUSTOM_PUBLIC_PATH = os.path.join(config.DATA_PATH, 'custom_public')


class MainHandler(tornado.web.StaticFileHandler):
class StaticHandler(tornado.web.StaticFileHandler):
"""为了使用Vue Router的history模式,把不存在的文件请求转发到index.html"""
async def get(self, path, include_body=True):
if path == '':
Expand Down Expand Up @@ -60,6 +60,11 @@ async def get(self):
})


class PingHandler(api.base.ApiHandler):
async def get(self):
self.set_status(204)


class UploadEmoticonHandler(api.base.ApiHandler):
async def post(self):
cfg = config.get_config()
Expand Down Expand Up @@ -103,12 +108,13 @@ def set_extra_headers(self, path):
ROUTES = [
(r'/api/server_info', ServerInfoHandler),
(r'/api/endpoints', ServiceDiscoveryHandler),
(r'/api/ping', PingHandler),
(r'/api/emoticon', UploadEmoticonHandler),
]
# 通配的放在最后
LAST_ROUTES = [
(rf'{EMOTICON_BASE_URL}/(.*)', tornado.web.StaticFileHandler, {'path': EMOTICON_UPLOAD_PATH}),
# 这个目录不保证文件内容不会变,还是不用缓存了
(r'/custom_public/(.*)', NoCacheStaticFileHandler, {'path': CUSTOM_PUBLIC_PATH}),
(r'/(.*)', MainHandler, {'path': config.WEB_ROOT}),
(r'/(.*)', StaticHandler, {'path': config.WEB_ROOT}),
]
2 changes: 1 addition & 1 deletion frontend/src/api/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ if (!process.env.BACKEND_DISCOVERY) {

async function testEndpoint(baseUrl) {
try {
let url = `${baseUrl}/api/server_info`
let url = `${baseUrl}/api/ping`
await axios.get(url, { timeout: 3 * 1000 })
sortedBaseUrls.push(baseUrl)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def request_get_urls(discovery_url):

async def test_endpoint(base_url):
try:
url = base_url + '/api/server_info'
url = base_url + '/api/ping'
async with http_session.get(url, timeout=aiohttp.ClientTimeout(total=3)) as res:
res.raise_for_status()
sorted_common_server_base_urls.append(base_url)
Expand Down

0 comments on commit de3712a

Please sign in to comment.