Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
575b66c5
authored
May 18, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support redirecting frontend url now (close #89)
parent
14662c3f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
2 deletions
+16
-2
README.md
+2
-0
router/main.go
+13
-1
router/web-router.go
+1
-1
No files found.
README.md
View file @
575b66c5
...
@@ -157,6 +157,8 @@ sudo service nginx restart
...
@@ -157,6 +157,8 @@ sudo service nginx restart
+ 例子:`
SESSION_SECRET=random_string
`
+ 例子:`
SESSION_SECRET=random_string
`
3. `
SQL_DSN
`:设置之后将使用指定数据库而非 SQLite。
3. `
SQL_DSN
`:设置之后将使用指定数据库而非 SQLite。
+ 例子:`
SQL_DSN=root:123456@tcp(localhost:3306)/one-api
`
+ 例子:`
SQL_DSN=root:123456@tcp(localhost:3306)/one-api
`
4. `
FRONTEND_BASE_URL
`:设置之后将使用指定的前端地址,而非后端地址。
+ 例子:`
FRONTEND_BASE_URL=https://openai.justsong.cn
`
### 命令行参数
### 命令行参数
1. `
--port
<port
_number
>
`: 指定服务器监听的端口号,默认为 `
3000
`。
1. `
--port
<port
_number
>
`: 指定服务器监听的端口号,默认为 `
3000
`。
...
...
router/main.go
View file @
575b66c5
...
@@ -2,12 +2,24 @@ package router
...
@@ -2,12 +2,24 @@ package router
import
(
import
(
"embed"
"embed"
"fmt"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"net/http"
"os"
"strings"
)
)
func
SetRouter
(
router
*
gin
.
Engine
,
buildFS
embed
.
FS
,
indexPage
[]
byte
)
{
func
SetRouter
(
router
*
gin
.
Engine
,
buildFS
embed
.
FS
,
indexPage
[]
byte
)
{
SetApiRouter
(
router
)
SetApiRouter
(
router
)
SetDashboardRouter
(
router
)
SetDashboardRouter
(
router
)
SetRelayRouter
(
router
)
SetRelayRouter
(
router
)
setWebRouter
(
router
,
buildFS
,
indexPage
)
frontendBaseUrl
:=
os
.
Getenv
(
"FRONTEND_BASE_URL"
)
if
frontendBaseUrl
==
""
{
SetWebRouter
(
router
,
buildFS
,
indexPage
)
}
else
{
frontendBaseUrl
=
strings
.
TrimSuffix
(
frontendBaseUrl
,
"/"
)
router
.
NoRoute
(
func
(
c
*
gin
.
Context
)
{
c
.
Redirect
(
http
.
StatusMovedPermanently
,
fmt
.
Sprintf
(
"%s%s"
,
frontendBaseUrl
,
c
.
Request
.
RequestURI
))
})
}
}
}
router/web-router.go
View file @
575b66c5
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
"one-api/middleware"
"one-api/middleware"
)
)
func
s
etWebRouter
(
router
*
gin
.
Engine
,
buildFS
embed
.
FS
,
indexPage
[]
byte
)
{
func
S
etWebRouter
(
router
*
gin
.
Engine
,
buildFS
embed
.
FS
,
indexPage
[]
byte
)
{
router
.
Use
(
gzip
.
Gzip
(
gzip
.
DefaultCompression
))
router
.
Use
(
gzip
.
Gzip
(
gzip
.
DefaultCompression
))
router
.
Use
(
middleware
.
GlobalWebRateLimit
())
router
.
Use
(
middleware
.
GlobalWebRateLimit
())
router
.
Use
(
middleware
.
Cache
())
router
.
Use
(
middleware
.
Cache
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment