mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-20 02:00:49 +00:00
Fix new static server setting not working
This commit is contained in:
parent
0d3233ecbd
commit
1be08573c5
4 changed files with 16 additions and 23 deletions
|
@ -5,7 +5,6 @@ import KilovoltWS from '@strimertul/kilovolt-client';
|
|||
interface ModuleConfig {
|
||||
configured: boolean;
|
||||
kv: boolean;
|
||||
static: boolean;
|
||||
twitch: boolean;
|
||||
stulbe: boolean;
|
||||
loyalty: boolean;
|
||||
|
@ -13,6 +12,7 @@ interface ModuleConfig {
|
|||
|
||||
interface HTTPConfig {
|
||||
bind: string;
|
||||
enable_static_server: boolean;
|
||||
path: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ export default function App(): React.ReactElement {
|
|||
return <div className="container">{t('system.loading')}</div>;
|
||||
}
|
||||
|
||||
const basepath = process.env.NODE_ENV === 'development' ? '/' : '/ui/';
|
||||
const basepath = '/ui/';
|
||||
|
||||
const routeItem = ({ route, name, subroutes }: RouteItem) => (
|
||||
<li key={route}>
|
||||
|
|
|
@ -10,12 +10,11 @@ export default function HTTPPage(
|
|||
params: RouteComponentProps<unknown>,
|
||||
): React.ReactElement {
|
||||
const { t } = useTranslation();
|
||||
const [moduleConfig, setModuleConfig] = useModule(modules.moduleConfig);
|
||||
const [httpConfig, setHTTPConfig] = useModule(modules.httpConfig);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const busy = moduleConfig === null || httpConfig === null;
|
||||
const active = moduleConfig?.static ?? false;
|
||||
const busy = httpConfig === null;
|
||||
const active = httpConfig?.enable_static_server ?? false;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -50,9 +49,9 @@ export default function HTTPPage(
|
|||
checked={active}
|
||||
onChange={(ev) =>
|
||||
dispatch(
|
||||
apiReducer.actions.moduleConfigChanged({
|
||||
...moduleConfig,
|
||||
static: ev.target.checked,
|
||||
apiReducer.actions.httpConfigChanged({
|
||||
...httpConfig,
|
||||
enable_static_server: ev.target.checked,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
@ -82,7 +81,6 @@ export default function HTTPPage(
|
|||
<button
|
||||
className="button"
|
||||
onClick={() => {
|
||||
dispatch(setModuleConfig(moduleConfig));
|
||||
dispatch(setHTTPConfig(httpConfig));
|
||||
}}
|
||||
>
|
||||
|
|
|
@ -15,14 +15,13 @@ import (
|
|||
)
|
||||
|
||||
type Server struct {
|
||||
Config ServerConfig
|
||||
db *database.DB
|
||||
logger logrus.FieldLogger
|
||||
server *http.Server
|
||||
frontend fs.FS
|
||||
hub *kv.Hub
|
||||
staticPath string
|
||||
mux *http.ServeMux
|
||||
Config ServerConfig
|
||||
db *database.DB
|
||||
logger logrus.FieldLogger
|
||||
server *http.Server
|
||||
frontend fs.FS
|
||||
hub *kv.Hub
|
||||
mux *http.ServeMux
|
||||
}
|
||||
|
||||
func NewServer(db *database.DB, log logrus.FieldLogger) (*Server, error) {
|
||||
|
@ -48,10 +47,6 @@ func (s *Server) SetHub(hub *kv.Hub) {
|
|||
s.hub = hub
|
||||
}
|
||||
|
||||
func (s *Server) SetStaticPath(path string) {
|
||||
s.staticPath = path
|
||||
}
|
||||
|
||||
func (s *Server) makeMux() *http.ServeMux {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
|
@ -63,8 +58,8 @@ func (s *Server) makeMux() *http.ServeMux {
|
|||
kv.ServeWs(s.hub, w, r)
|
||||
})
|
||||
}
|
||||
if s.staticPath != "" {
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(s.staticPath))))
|
||||
if s.Config.EnableStaticServer {
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(s.Config.Path))))
|
||||
}
|
||||
|
||||
return mux
|
||||
|
|
Loading…
Reference in a new issue