-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,984 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,7 @@ Thumbs.db | |
*.tmp | ||
*.swp | ||
*~ | ||
.vercel | ||
|
||
# Node | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Package api 提供 Serverless HTTP API 服务 | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
"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 == "" { | ||
slog.Info("no config url provided, using default config") | ||
return config.DefaultConfig(), nil | ||
} | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Vercel 部署 | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgit.luolix.top%2Fwayjam%2Ftv-mixproxy&env=TV_MIXPROXY_CFG_URL&project-name=tv-mixproxy&repository-name=tv-mixproxy) | ||
|
||
|
||
配置: Vercel 配置 `TV_MIXPROXY_CFG_URL` 环境变量来指定配置文件的 URL。配置文件可以使用以下几种方式来存储: | ||
|
||
1. Vercel Blob | ||
2. Github + jsDelivr CDN | ||
3. 其他 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.