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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

Go
繁華開滿天機 2021-11-08 10:25:14
我寫了一個 golang 網(wǎng)絡服務器,我之前提供靜態(tài)資源,但在改變我的項目結(jié)構后,這不再有效。這是我的項目結(jié)構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,    },}當我點擊 localhost:8200 時,我在加載 test.js 時得到 404,但 index.html 正在被點擊。以前,這是不使用 http.FileServer 來提供靜態(tài)資源的問題,但我現(xiàn)在正在使用它。我已經(jīng)嘗試過 index.html 中路徑的其他變體src= "static/scripts/test.js"src= "../static/scripts/test.js"到底是怎么回事?
查看完整描述

1 回答

?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

請嘗試以下操作:


// 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"


查看完整回答
反對 回復 2021-11-08
  • 1 回答
  • 0 關注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號