feat: added format code to config editor
parent
5cc9068f5f
commit
594c61a0ff
@ -1,33 +1,47 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/server/pkg/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"github.com/0xJacky/Nginx-UI/server/pkg/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func BuildNginxConfig(c *gin.Context) {
|
||||
var ngxConf nginx.NgxConfig
|
||||
if !BindAndValid(c, &ngxConf) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": ngxConf.BuildConfig(),
|
||||
})
|
||||
var ngxConf nginx.NgxConfig
|
||||
if !BindAndValid(c, &ngxConf) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": ngxConf.BuildConfig(),
|
||||
})
|
||||
}
|
||||
|
||||
func TokenizeNginxConfig(c *gin.Context) {
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
if !BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
if !BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
ngxConfig := nginx.ParseNgxConfigByContent(json.Content)
|
||||
ngxConfig := nginx.ParseNgxConfigByContent(json.Content)
|
||||
|
||||
c.JSON(http.StatusOK, ngxConfig)
|
||||
c.JSON(http.StatusOK, ngxConfig)
|
||||
|
||||
}
|
||||
|
||||
func FormatNginxConfig(c *gin.Context) {
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
if !BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": nginx.FmtCode(json.Content),
|
||||
})
|
||||
}
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php;
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
location / {
|
||||
try_files $uri $uri/ /server.php?$query_string;
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
# Nginx UI Template Start
|
||||
# Name: Nginx UI
|
||||
# Description[en]: Nginx UI Config Template
|
||||
# Description[zh_CN]: Nginx UI 配置模板
|
||||
# Author: @0xJacky
|
||||
# Nginx UI Template End
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name ;
|
||||
rewrite ^(.*)$ https://$host$1 permanent;
|
||||
}
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name ;
|
||||
ssl_certificate ;
|
||||
ssl_certificate_key ;
|
||||
location / {
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_pass http://127.0.0.1:9000/;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
# Nginx UI Template Start
|
||||
# Name: WordPress-PHP8.1
|
||||
# Description[en]: WordPress PHP 8.1 Config Template
|
||||
# Description[zh_CN]: WordPress PHP 8.1 配置模板
|
||||
# Author: @0xJacky
|
||||
# Nginx UI Template End
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name ;
|
||||
rewrite ^(.*)$ https://$host$1 permanent;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name ;
|
||||
ssl_certificate ;
|
||||
ssl_certificate_key ;
|
||||
root ;
|
||||
index index.php;
|
||||
|
||||
location ~ [^/]\.php(/|$) {
|
||||
try_files $uri =404;
|
||||
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi.conf;
|
||||
}
|
||||
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$args;
|
||||
}
|
||||
|
||||
# Add trailing slash to */wp-admin requests.
|
||||
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
|
||||
|
||||
location /.well-known {
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real_IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
|
||||
proxy_pass http://127.0.0.1:{{ HTTP01PORT }};
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue