Skip to content

Commit

Permalink
feat: support vercel deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
wayjam committed Nov 3, 2024
1 parent e9afe72 commit 3a87268
Show file tree
Hide file tree
Showing 14 changed files with 2,972 additions and 134 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ Thumbs.db
*.tmp
*.swp
*~
.vercel

# Node
node_modules/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ TV MixProxy 是一个用于混合不同 电视接口 并提供服务的工具。
## 功能特点

- 支持TVBox单仓库和TvBox多仓库设置
- 支持代理 EPG
- 支持代理 M3U 媒体播放列表
- 可自定义不同配置字段的混合选项
- 定期更新源配置

Expand Down
54 changes: 54 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package api

import (
"fmt"
"net/http"
"os"

"github.com/gofiber/fiber/v3/middleware/adaptor"
"github.com/spf13/viper"
"github.com/wayjam/tv-mixproxy/config"
"github.com/wayjam/tv-mixproxy/server"
)

var (
app http.Handler
)

// Entrypoint
func Handler(w http.ResponseWriter, r *http.Request) {
app.ServeHTTP(w, r)
}

func init() {
// load config from remote
cfg, err := loadRemoteConfig()
if err != nil {
panic(err)
}

server := server.NewServer(cfg)
if err := server.PreRun(); err != nil {
panic(err)
}
app = adaptor.FiberApp(server.App())
}

func loadRemoteConfig() (*config.Config, error) {
configURL := os.Getenv("TV_MIXPROXY_CFG_URL")
if configURL == "" {
return nil, fmt.Errorf("failed to load config from remote %s", configURL)
}

resp, err := http.Get(configURL)
if err != nil {
return nil, fmt.Errorf("failed to get config from remote %s", err)
}
defer resp.Body.Close()

v := viper.New()
v.SetConfigType("yaml")
v.ReadConfig(resp.Body)

return config.UnmarshalConfig(v)
}
11 changes: 9 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ func LoadServerConfig(cfgFile string) (*Config, error) {
return nil, fmt.Errorf("error reading config file: %v", err)
}

cfg, err := UnmarshalConfig(v)
if err != nil {
return nil, fmt.Errorf("unable to decode into struct: %v", err)
}

return cfg, nil
}

func UnmarshalConfig(v *viper.Viper) (*Config, error) {
var cfg Config
if err := v.Unmarshal(&cfg); err != nil {
return nil, fmt.Errorf("unable to decode into struct: %v", err)
}

cfg.Fixture()

return &cfg, nil
}
1 change: 1 addition & 0 deletions docs/vercel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Vercel 部署
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/wayjam/tv-mixproxy

go 1.22.3
go 1.21

replace github.com/jamesnetherton/m3u => github.com/wayjam/m3u v0.0.0-20241029160035-d1ef859bcb0c
toolchain go1.23.2

require (
github.com/gofiber/fiber/v3 v3.0.0-beta.3
Expand Down
Loading

0 comments on commit 3a87268

Please sign in to comment.