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