Skip to content

Commit 10ae1f6

Browse files
committed
feat: added reload nginx button to header
1 parent b89d962 commit 10ae1f6

File tree

6 files changed

+58
-7
lines changed

6 files changed

+58
-7
lines changed

frontend/src/api/ngx.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const ngx = {
1111

1212
format_code(content: string) {
1313
return http.post('/ngx/format_code', {content})
14+
},
15+
16+
reload() {
17+
return http.post('/nginx/reload')
1418
}
1519
}
1620

frontend/src/layouts/HeaderLayout.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import SetLanguage from '@/components/SetLanguage/SetLanguage.vue'
33
import gettext from '@/gettext'
44
import {message} from 'ant-design-vue'
55
import auth from '@/api/auth'
6-
import {HomeOutlined, LogoutOutlined, MenuUnfoldOutlined} from '@ant-design/icons-vue'
6+
import {HomeOutlined, LogoutOutlined, MenuUnfoldOutlined, ReloadOutlined} from '@ant-design/icons-vue'
77
import {useRouter} from 'vue-router'
8+
import ngx from '@/api/ngx'
89
910
const {$gettext} = gettext
1011
@@ -18,6 +19,13 @@ function logout() {
1819
})
1920
}
2021
22+
function reload_nginx() {
23+
ngx.reload().then(r => {
24+
message.success($gettext('Nginx reloaded successfully'))
25+
}).catch(e => {
26+
message.error($gettext('Server error') + ' ' + e?.message)
27+
})
28+
}
2129
</script>
2230

2331
<template>
@@ -26,17 +34,29 @@ function logout() {
2634
<MenuUnfoldOutlined @click="$emit('clickUnFold')"/>
2735
</div>
2836

29-
<div class="user-wrapper">
37+
<a-space class="user-wrapper" :size="24">
3038
<set-language class="set_lang"/>
3139

3240
<a href="/">
3341
<HomeOutlined/>
3442
</a>
3543

36-
<a @click="logout" style="margin-left: 20px">
44+
<a-popconfirm
45+
:title="$gettext('Do you want to reload Nginx?')"
46+
:ok-text="$gettext('Yes')"
47+
:cancel-text="$gettext('No')"
48+
@confirm="reload_nginx"
49+
placement="bottomRight"
50+
>
51+
<a>
52+
<ReloadOutlined/>
53+
</a>
54+
</a-popconfirm>
55+
56+
<a @click="logout">
3757
<LogoutOutlined/>
3858
</a>
39-
</div>
59+
</a-space>
4060
</div>
4161
</template>
4262

@@ -75,11 +95,10 @@ function logout() {
7595
7696
.user-wrapper {
7797
position: fixed;
78-
right: 20px;
98+
right: 28px;
7999
}
80100
81101
.set_lang {
82102
display: inline;
83-
margin-right: 25px;
84103
}
85104
</style>

frontend/src/views/domain/DomainEdit.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function on_change_enabled(checked: boolean) {
218218

219219
<footer-tool-bar>
220220
<a-space>
221-
<a-button @click="$router.go(-1)">
221+
<a-button @click="$router.push('/domain/list')">
222222
<translate>Back</translate>
223223
</a-button>
224224
<a-button type="primary" @click="save" :loading="saving">

frontend/yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,11 @@
636636
resolved "https://registry.npmmirror.com/@types/node/-/node-18.11.18.tgz#8dfb97f0da23c2293e554c5a50d61ef134d7697f"
637637
integrity sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==
638638

639+
"@types/nprogress@^0.2.0":
640+
version "0.2.0"
641+
resolved "https://registry.yarnpkg.com/@types/nprogress/-/nprogress-0.2.0.tgz#86c593682d4199212a0509cc3c4d562bbbd6e45f"
642+
integrity sha512-1cYJrqq9GezNFPsWTZpFut/d4CjpZqA0vhqDUPFWYKF1oIyBz5qnoYMzR+0C/T96t3ebLAC1SSnwrVOm5/j74A==
643+
639644
"@types/parse-json@^4.0.0":
640645
version "4.0.0"
641646
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
@@ -2136,6 +2141,11 @@ normalize-url@^6.0.1:
21362141
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a"
21372142
integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==
21382143

2144+
nprogress@^0.2.0:
2145+
version "0.2.0"
2146+
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
2147+
integrity sha512-I19aIingLgR1fmhftnbWWO3dXc0hSxqHQHQb3H8m+K3TnEn/iSeTZZOyvKXWqQESMwuUVnatlCnZdLBZZt2VSA==
2148+
21392149
nth-check@^2.0.1:
21402150
version "2.1.1"
21412151
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.1.1.tgz#c9eab428effce36cd6b92c924bdb000ef1f1ed1d"

server/api/ngx.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/0xJacky/Nginx-UI/server/pkg/nginx"
55
"github.com/gin-gonic/gin"
66
"net/http"
7+
"strings"
78
)
89

910
func BuildNginxConfig(c *gin.Context) {
@@ -47,3 +48,18 @@ func FormatNginxConfig(c *gin.Context) {
4748
"content": nginx.FmtCode(json.Content),
4849
})
4950
}
51+
52+
func ReloadNginx(c *gin.Context) {
53+
output := nginx.Reload()
54+
55+
if output != "" && strings.Contains(output, "error") {
56+
c.JSON(http.StatusInternalServerError, gin.H{
57+
"message": output,
58+
})
59+
return
60+
}
61+
62+
c.JSON(http.StatusOK, gin.H{
63+
"message": "ok",
64+
})
65+
}

server/router/routers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func InitRouter() *gin.Engine {
6262
g.POST("ngx/tokenize_config", api.TokenizeNginxConfig)
6363
// Format nginx configuration code
6464
g.POST("ngx/format_code", api.FormatNginxConfig)
65+
// nginx reload
66+
g.POST("nginx/reload", api.ReloadNginx)
6567

6668
g.POST("domain/:name/enable", api.EnableDomain)
6769
g.POST("domain/:name/disable", api.DisableDomain)

0 commit comments

Comments
 (0)