fix: lib mode in subpath

pull/39/head
Evan 2021-10-24 15:06:02 +08:00
parent 40549e6552
commit 54f1d3278f
12 changed files with 21 additions and 16 deletions

View File

@ -7,7 +7,7 @@ steps:
commands:
- git tag $DRONE_TAG
- bash release.sh cmd/configui/main.go
- echo -n "latest,$DRONE_TAG" > .tags
- echo -n "latest,${DRONE_TAG#v}" > .tags
- name: gitea_release
image: plugins/gitea-release

2
app.go
View File

@ -24,6 +24,7 @@ type Editor struct {
type Page struct {
AppName string
BaseUrl string
Version string
Build string
Files []ActiveFile
@ -62,6 +63,7 @@ func (cui *ConfigUI) App(w http.ResponseWriter, r *http.Request) {
}
data := Page{
AppName: cui.AppName,
BaseUrl: cui.BaseUrl,
File: ActiveFile{},
Files: Files,
Editor: Editor{

View File

@ -29,6 +29,7 @@ var Ext2Mode map[string]string = map[string]string{
type ConfigUI struct {
AppName string `json:"app_name"`
BaseUrl string `json:"base_url"`
ConfigPath string `json:"config_path"`
NoReconfig bool `json:"no_reconfig"`
@ -37,7 +38,6 @@ type ConfigUI struct {
Files []*File `json:"files"`
fileIndex map[string]int
// TODO
ResultBellow bool `json:"result_bellow"`
HideConfig bool `json:"hide_config"`
@ -63,6 +63,7 @@ func New() *ConfigUI {
return &ConfigUI{
fileIndex: map[string]int{},
AppName: "ConfigUI",
BaseUrl: "/",
PublicFS: public.FS,
TmplFS: tmplFS,
tmpl: tmpl,
@ -109,6 +110,7 @@ func (cui *ConfigUI) LoadConfig(confstr string) error {
cui.LogPath = tmpConf.LogPath
cui.NoReconfig = tmpConf.NoReconfig
cui.AppName = tmpConf.AppName
cui.BaseUrl = tmpConf.BaseUrl
// NOT implemented
cui.ResultBellow = tmpConf.ResultBellow

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,7 @@ func (cui *ConfigUI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (cui *ConfigUI) middleware(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
// log.Println(r.URL)
rw := &CuiResponseWriter{w, 0}
defer catch(rw, r)
ip := GetIP(r)

View File

@ -2,7 +2,7 @@
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(/public/assets/mat.ttf) format('truetype');
src: url(../assets/mat.ttf) format('truetype');
}
.material-icons {

View File

@ -6,8 +6,8 @@
</p>
</div>
</footer>
<script src="/public/ace/js/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="/public/ace/js/ext-beautify.js" type="text/javascript" charset="utf-8"></script>
<script src="{{.BaseUrl}}public/ace/js/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="{{.BaseUrl}}public/ace/js/ext-beautify.js" type="text/javascript" charset="utf-8"></script>
{{template "base/script" .}}
<!-- <script src="/public/js/main.js"></script> -->
</body>

View File

@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{.AppName}}</title>
<link rel="stylesheet" href="/public/css/main.css">
<link rel="stylesheet" href="{{.BaseUrl}}public/css/main.css">
</head>
<body>
{{end}}

View File

@ -7,7 +7,7 @@ async function FileGet(follower=false){
let f = ''
if (Active == 'ConfigUI') {
if (follower) f = '?f=true'
const res = await fetch('/api/conf'+f)
const res = await fetch('{{.BaseUrl}}api/conf'+f)
.catch(err=>{console.log(err);return;});
const body = await res.text();
if(!res.ok){
@ -18,7 +18,7 @@ async function FileGet(follower=false){
}
else {
if (follower) f = '&f=true'
const res = await fetch('/api/file?name=' + Active + f)
const res = await fetch('{{.BaseUrl}}api/file?name=' + Active + f)
.catch(err=>{console.log(err);return;});
const body = await res.json();
if(!res.ok){
@ -31,7 +31,7 @@ async function FileGet(follower=false){
async function FileSave(){
if (Active == '{{.AppName}}') {
const res = await fetch('/api/conf', {
const res = await fetch('{{.BaseUrl}}api/conf', {
method: 'POST',
body: editor.getValue(),
headers: new Headers({
@ -45,7 +45,7 @@ async function FileSave(){
else Catch(res)
}
else {
const res = await fetch('/api/file', {
const res = await fetch('{{.BaseUrl}}api/file', {
method: 'POST',
body: JSON.stringify({"name":Active,"data":editor.getValue()}),
headers: new Headers({
@ -62,7 +62,7 @@ async function FileApply(){
return;
}
else {
const res = await fetch('/api/apply?name='+ Active, {
const res = await fetch('{{.BaseUrl}}api/apply?name='+ Active, {
method: 'POST',
});
if(!res.ok){

View File

@ -9,7 +9,7 @@
<li>
<a class="has-tooltip-arrow {{if eq $.File.Name .Name }}is-active{{end}}"
data-tooltip="{{.Path}}"
href="/?name={{.Name}}"
href="{{$.BaseUrl}}?name={{.Name}}"
>{{ .Name }}</a>
</li>
{{ end }}
@ -22,7 +22,7 @@
<li>
<a class="has-tooltip-arrow {{if eq .File.Name .AppName }}is-active{{end}}"
data-tooltip="{{$.File.Path}}"
href="/"
href="{{.BaseUrl}}"
>Config</a></li>
</ul>
{{end}}

View File

@ -105,7 +105,7 @@
<p class="control">
<a class="button is-small has-tooltip-arrow" data-tooltip="Download"
href="/api/export?name={{.File.Name}}">
href="{{.BaseUrl}}api/export?name={{.File.Name}}">
<span class="icon is-small"><span class="material-icons">
download
</span></span>

View File

@ -19,7 +19,7 @@ var Active = "{{.File.Name}}";
{{template "components/menu" .}}
</div>
<div class="box has-text-centered">
<a href="/api/export" class="button is-small">Export Files</a>
<a href="{{.BaseUrl}}api/export" class="button is-small">Export Files</a>
</div>
</div>
<div class="column">