2023-03-28 19:39:22 +01:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 09:12:13 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 19:39:22 +01:00
|
|
|
|
2020-09-23 12:37:33 +01:00
|
|
|
package uiserver
|
|
|
|
|
|
|
|
import (
|
2022-05-31 15:33:56 -04:00
|
|
|
"io/fs"
|
2020-09-23 12:37:33 +01:00
|
|
|
)
|
|
|
|
|
2022-05-31 15:33:56 -04:00
|
|
|
// bufIndexFS is an implementation of fs.FS that intercepts requests for
|
2020-09-23 12:37:33 +01:00
|
|
|
// the index.html file and returns a pre-rendered file from memory.
|
|
|
|
type bufIndexFS struct {
|
2022-05-31 15:33:56 -04:00
|
|
|
fs fs.FS
|
|
|
|
bufIndex fs.File
|
2020-09-23 12:37:33 +01:00
|
|
|
}
|
|
|
|
|
2022-05-31 15:33:56 -04:00
|
|
|
func (fs *bufIndexFS) Open(name string) (fs.File, error) {
|
|
|
|
if name == "index.html" {
|
|
|
|
return fs.bufIndex, nil
|
2020-09-23 12:37:33 +01:00
|
|
|
}
|
|
|
|
return fs.fs.Open(name)
|
|
|
|
}
|