第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

無(wú)法使用 golang 服務(wù)器定位靜態(tài)腳本

無(wú)法使用 golang 服務(wù)器定位靜態(tài)腳本

我寫(xiě)了一個(gè) golang 網(wǎng)絡(luò)服務(wù)器,我之前提供靜態(tài)資源,但在改變我的項(xiàng)目結(jié)構(gòu)后,這不再有效。這是我的項(xiàng)目結(jié)構(gòu)ProjectFolder/    node_modules/    scripts/       test.es6.js    server/       handlers.go       main.go       routes.go    static/       scripts/          test.js          test.js.map    Gruntfile.js    index.html    package.json這是我的 index.html<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script><script type="text/javacript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.1/backbone-min.js"></script><script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script><script type="text/javascript" src="/static/scripts/test.js"</script><body>    <div id="chart"></div></body>這是我的routes.gofunc NewRouter() *mux.Router {    router := mux.NewRouter().StrictSlash(true)    for _, route := range routes {        router.            Methods(route.Method).            Path(route.Pattern).            Name(route.Name).            Handler(route.HandlerFunc)    }    for pathName, pathValue := range staticPaths {        pathPrefix := "/" + pathName + "/"        fmt.Println(pathPrefix)        fmt.Println(pathValue)        router.PathPrefix(pathPrefix).Handler(http.StripPrefix(pathPrefix, http.FileServer(http.Dir(pathValue))))    }    // router.PathPrefix("/static/scripts").Handler(http.FileServer(http.Dir("./static/scripts/")))    return router}var staticDirectory = "/static"var staticPaths = map[string]string{    "scripts": staticDirectory + "/scripts/",}var routes = Routes{    Route{        "Index",        "GET",        "/",        Index,    },}當(dāng)我點(diǎn)擊 localhost:8200 時(shí),我在加載 test.js 時(shí)得到 404,但 index.html 正在被點(diǎn)擊。以前,這是不使用 http.FileServer 來(lái)提供靜態(tài)資源的問(wèn)題,但我現(xiàn)在正在使用它。我已經(jīng)嘗試過(guò) index.html 中路徑的其他變體src= "static/scripts/test.js"src= "../static/scripts/test.js"到底是怎么回事?
查看完整描述

1 回答

?
撒科打諢

TA貢獻(xiàn)1934條經(jīng)驗(yàn) 獲得超2個(gè)贊

請(qǐng)嘗試以下操作:


// Create new router.

gorillaMux := mux.NewRouter()


// Match /res/ prefix to local /res/ folder.

gorillaMux.PathPrefix("/res/").Handler(http.StripPrefix("/res/", http.FileServer(http.Dir("./res/"))))

這將使http://example.com/res/js/script.js尋找./res/js/script.js


因此,您必須在 HTML 中完全限定您的資源: src= "/static/scripts/test.js"


查看完整回答
反對(duì) 回復(fù) 2021-11-08
  • 1 回答
  • 0 關(guān)注
  • 181 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)