dongzaotiao2863 2017-01-28 13:23
浏览 32

大猩猩mux,不包括扩展请求

An attempt to configure go server routing with github.com/gorilla/mux to respond to all requests with index.html but exclude requests with extension .jpg|.js|.png

Static files excluded due to extension will be routed to FileServer. configured.

Failed Attempt

  func main() {
        r := mux.NewRouter()

        r.HandleFunc("/{path:^.*([!js|jpg|png|gif])$}", func(w http.ResponseWriter, r *http.Request) {
            http.ServeFile(w, r, "dist/index.html")
        })

        r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("dist"))))

        http.Handle("/", r)
        http.ListenAndServe(":8000", nil)
    }
  • 写回答

2条回答 默认 最新

  • dongshu4755 2017-01-28 14:19
    关注

    This "^.*([!js|jpg|png|gif])$}" is not a valid regular expession for matching string that does not have .jpg|.js|.png

    However, In golang Negative lookahead isn't supported for technical reasons, specifically because it conflicts with the O(n)-time guarantees of the library.

    I would suggest you to do it other way around ie, add handlers for png,js,css files etc to serve the files as such

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?