之前有寫過利用百度云加速邊緣計算功能設(shè)置自義錯誤的案例,今天我們來學(xué)習(xí)下利用邊緣計算功能設(shè)置網(wǎng)站判斷移動端和PC端頁面跳轉(zhuǎn)。
首先還是老步驟,先在我的函數(shù)里添加以下函數(shù)
編輯
輸入以下代碼,修改自己的相應(yīng)的網(wǎng)址,并保存:
// PC端頁面
const PCPage = ‘https://你的PC頁網(wǎng)址’// 移動端頁面
const MobilePage = ‘https://你的移動頁網(wǎng)址’async function handleRequest(request) {
ua = request.headers.get(‘user-agent’)
// 如果是移動端,則返回移動端頁面
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua))
return await fetch(MobilePage)
// 如果是PC端,則返回PC端頁面
else
return await fetch(PCPage)
}addEventListener(‘fetch’, event => {
event.respondWith(handleRequest(event.request))
})
返域名管理,進(jìn)入域名管理左邊的功能,邊緣計算:
選好函數(shù):