mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 10:55:51 +02:00
fix: add template in "site-add" cause nginx error #796
This commit is contained in:
parent
b9822be86d
commit
a9520c1169
4 changed files with 26 additions and 26 deletions
|
@ -3,7 +3,7 @@ package template
|
||||||
import "github.com/gin-gonic/gin"
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
func InitRouter(r *gin.RouterGroup) {
|
func InitRouter(r *gin.RouterGroup) {
|
||||||
r.GET("templates", GetTemplate)
|
r.GET("default_site_template", GetDefaultSiteTemplate)
|
||||||
r.GET("templates/configs", GetTemplateConfList)
|
r.GET("templates/configs", GetTemplateConfList)
|
||||||
r.GET("templates/blocks", GetTemplateBlockList)
|
r.GET("templates/blocks", GetTemplateBlockList)
|
||||||
r.GET("templates/block/:name", GetTemplateBlock)
|
r.GET("templates/block/:name", GetTemplateBlock)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTemplate(c *gin.Context) {
|
func GetDefaultSiteTemplate(c *gin.Context) {
|
||||||
var ngxConfig *nginx.NgxConfig
|
var ngxConfig *nginx.NgxConfig
|
||||||
|
|
||||||
ngxConfig = &nginx.NgxConfig{
|
ngxConfig = &nginx.NgxConfig{
|
||||||
|
|
|
@ -43,8 +43,8 @@ class SiteCurd extends Curd<Site> {
|
||||||
return http.post(`${this.baseUrl}/${oldName}/rename`, { new_name: newName })
|
return http.post(`${this.baseUrl}/${oldName}/rename`, { new_name: newName })
|
||||||
}
|
}
|
||||||
|
|
||||||
get_template() {
|
get_default_template() {
|
||||||
return http.get('template')
|
return http.get('default_site_template')
|
||||||
}
|
}
|
||||||
|
|
||||||
add_auto_cert(domain: string, data: AutoCertRequest) {
|
add_auto_cert(domain: string, data: AutoCertRequest) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import LocationEditor from '@/views/site/ngx_conf/LocationEditor.vue'
|
||||||
import NgxConfigEditor from '@/views/site/ngx_conf/NgxConfigEditor.vue'
|
import NgxConfigEditor from '@/views/site/ngx_conf/NgxConfigEditor.vue'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
|
|
||||||
const ngx_config: NgxConfig = reactive({
|
const ngxConfig: NgxConfig = reactive({
|
||||||
name: '',
|
name: '',
|
||||||
servers: [{
|
servers: [{
|
||||||
directives: [],
|
directives: [],
|
||||||
|
@ -15,28 +15,28 @@ const ngx_config: NgxConfig = reactive({
|
||||||
}],
|
}],
|
||||||
})
|
})
|
||||||
|
|
||||||
const current_step = ref(0)
|
const currentStep = ref(0)
|
||||||
|
|
||||||
const enabled = ref(true)
|
const enabled = ref(true)
|
||||||
|
|
||||||
const auto_cert = ref(false)
|
const autoCert = ref(false)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
init()
|
init()
|
||||||
})
|
})
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
site.get_template().then(r => {
|
site.get_default_template().then(r => {
|
||||||
Object.assign(ngx_config, r.tokenized)
|
Object.assign(ngxConfig, r.tokenized)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
return ngx.build_config(ngx_config).then(r => {
|
return ngx.build_config(ngxConfig).then(r => {
|
||||||
site.save(ngx_config.name, { name: ngx_config.name, content: r.content, overwrite: true }).then(() => {
|
site.save(ngxConfig.name, { name: ngxConfig.name, content: r.content, overwrite: true }).then(() => {
|
||||||
message.success($gettext('Saved successfully'))
|
message.success($gettext('Saved successfully'))
|
||||||
|
|
||||||
site.enable(ngx_config.name).then(() => {
|
site.enable(ngxConfig.name).then(() => {
|
||||||
message.success($gettext('Enabled successfully'))
|
message.success($gettext('Enabled successfully'))
|
||||||
window.scroll({ top: 0, left: 0, behavior: 'smooth' })
|
window.scroll({ top: 0, left: 0, behavior: 'smooth' })
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
@ -51,7 +51,7 @@ async function save() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
function goto_modify() {
|
function goto_modify() {
|
||||||
router.push(`/sites/${ngx_config.name}`)
|
router.push(`/sites/${ngxConfig.name}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_another() {
|
function create_another() {
|
||||||
|
@ -59,7 +59,7 @@ function create_another() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const has_server_name = computed(() => {
|
const has_server_name = computed(() => {
|
||||||
const servers = ngx_config.servers
|
const servers = ngxConfig.servers
|
||||||
|
|
||||||
for (const server of Object.values(servers)) {
|
for (const server of Object.values(servers)) {
|
||||||
for (const directive of Object.values(server.directives!)) {
|
for (const directive of Object.values(server.directives!)) {
|
||||||
|
@ -73,40 +73,40 @@ const has_server_name = computed(() => {
|
||||||
|
|
||||||
async function next() {
|
async function next() {
|
||||||
await save()
|
await save()
|
||||||
current_step.value++
|
currentStep.value++
|
||||||
}
|
}
|
||||||
|
|
||||||
const ngx_directives = computed(() => {
|
const ngx_directives = computed(() => {
|
||||||
return ngx_config.servers[0].directives
|
return ngxConfig.servers[0].directives
|
||||||
})
|
})
|
||||||
|
|
||||||
provide('save_config', save)
|
provide('save_config', save)
|
||||||
provide('ngx_directives', ngx_directives)
|
provide('ngx_directives', ngx_directives)
|
||||||
provide('ngx_config', ngx_config)
|
provide('ngx_config', ngxConfig)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ACard :title="$gettext('Add Site')">
|
<ACard :title="$gettext('Add Site')">
|
||||||
<div class="domain-add-container">
|
<div class="domain-add-container">
|
||||||
<ASteps
|
<ASteps
|
||||||
:current="current_step"
|
:current="currentStep"
|
||||||
size="small"
|
size="small"
|
||||||
>
|
>
|
||||||
<AStep :title="$gettext('Base information')" />
|
<AStep :title="$gettext('Base information')" />
|
||||||
<AStep :title="$gettext('Configure SSL')" />
|
<AStep :title="$gettext('Configure SSL')" />
|
||||||
<AStep :title="$gettext('Finished')" />
|
<AStep :title="$gettext('Finished')" />
|
||||||
</ASteps>
|
</ASteps>
|
||||||
<template v-if="current_step === 0">
|
<template v-if="currentStep === 0">
|
||||||
<AForm layout="vertical">
|
<AForm layout="vertical">
|
||||||
<AFormItem :label="$gettext('Configuration Name')">
|
<AFormItem :label="$gettext('Configuration Name')">
|
||||||
<AInput v-model:value="ngx_config.name" />
|
<AInput v-model:value="ngxConfig.name" />
|
||||||
</AFormItem>
|
</AFormItem>
|
||||||
</AForm>
|
</AForm>
|
||||||
|
|
||||||
<DirectiveEditor />
|
<DirectiveEditor />
|
||||||
<br>
|
<br>
|
||||||
<LocationEditor
|
<LocationEditor
|
||||||
:locations="ngx_config.servers[0].locations"
|
:locations="ngxConfig.servers[0].locations"
|
||||||
:current-server-index="0"
|
:current-server-index="0"
|
||||||
/>
|
/>
|
||||||
<br>
|
<br>
|
||||||
|
@ -123,26 +123,26 @@ provide('ngx_config', ngx_config)
|
||||||
<br>
|
<br>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-else-if="current_step === 1">
|
<template v-else-if="currentStep === 1">
|
||||||
<NgxConfigEditor
|
<NgxConfigEditor
|
||||||
v-model:auto-cert="auto_cert"
|
v-model:auto-cert="autoCert"
|
||||||
:enabled="enabled"
|
:enabled="enabled"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<ASpace v-if="current_step < 2">
|
<ASpace v-if="currentStep < 2">
|
||||||
<AButton
|
<AButton
|
||||||
type="primary"
|
type="primary"
|
||||||
:disabled="!ngx_config.name || !has_server_name"
|
:disabled="!ngxConfig.name || !has_server_name"
|
||||||
@click="next"
|
@click="next"
|
||||||
>
|
>
|
||||||
{{ $gettext('Next') }}
|
{{ $gettext('Next') }}
|
||||||
</AButton>
|
</AButton>
|
||||||
</ASpace>
|
</ASpace>
|
||||||
<AResult
|
<AResult
|
||||||
v-else-if="current_step === 2"
|
v-else-if="currentStep === 2"
|
||||||
status="success"
|
status="success"
|
||||||
:title="$gettext('Domain Config Created Successfully')"
|
:title="$gettext('Domain Config Created Successfully')"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue