Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add AppInstance config #647

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare module '*.less';
interface Window {
gConfig: {
databaseName: string;
appInstance: 'single' | 'multi';
};
__ngqlRunner__: any;
}
6 changes: 5 additions & 1 deletion app/stores/moduleConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export class ModuleConfigurationStore implements IModuleConfiguration {
disableConfigDownload: false,
disableLogDownload: false,
needPwdConfirm: true,
supportDatasourceType: [IDatasourceType.Local, IDatasourceType.S3, IDatasourceType.SFTP],
supportDatasourceType: [
window.gConfig?.appInstance === 'single' && IDatasourceType.Local,
IDatasourceType.S3,
IDatasourceType.SFTP,
].filter(Boolean),
supportS3Platform: [ES3Platform.AWS, ES3Platform.OSS, ES3Platform.Tecent, ES3Platform.Customize],
disableConfigMore: false,
};
Expand Down
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
<!-- Global Event Tracking -->
<script>var global = typeof global !== 'undefined' ? global : window;</script>
<script>
window.gConfig = { databaseName: "NebulaGraph" }
<% if (initProps.NODE_ENV === 'development') { %>
window.gConfig = { appInstance: <%- JSON.stringify(initProps.appInstance) %>, databaseName: "NebulaGraph" }
<% } else { %>
window.gConfig = { appInstance: "{{.appInstance}}", databaseName: "NebulaGraph" }
<% } %>
</script>
<style>
@-webkit-keyframes square-spin {
Expand Down
3 changes: 3 additions & 0 deletions server/api/studio/etc/studio-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Host: 0.0.0.0
Port: 9000
MaxBytes: 1073741824
Timeout: 60000
# single(single-instance) or multi(multi-instance), default is single
# multi-instance: local data storage will be prohibited to ensure consistency across multiple instances
# AppInstance: "multi"
Log:
Mode: file
Level: info
Expand Down
3 changes: 2 additions & 1 deletion server/api/studio/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func GetConfig() *Config {

type Config struct {
rest.RestConf
Debug struct {
AppInstance string `json:",default=single"`
Debug struct {
Enable bool
}
Auth struct {
Expand Down
17 changes: 17 additions & 0 deletions server/api/studio/pkg/middleware/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@ package utils
import (
"io/fs"
"net/http"
"path/filepath"
"text/template"

"github.com/vesoft-inc/go-pkg/middleware"
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc"
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/ecode"
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/utils"
)

func AssetsMiddlewareWithCtx(svcCtx *svc.ServiceContext, embedAssets fs.FS) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if filepath.Ext(r.URL.Path) == "" {
tpl, err := template.ParseFS(embedAssets, "assets/index.html")
withErrorMessage := utils.ErrMsgWithLogger(r.Context())
if err != nil {
svcCtx.ResponseHandler.Handle(w, r, nil, withErrorMessage(ecode.ErrInternalServer, err))
return
}

w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
tpl.Execute(w, map[string]any{"appInstance": svcCtx.Config.AppInstance})
return
}

handler := middleware.NewAssetsHandler(middleware.AssetsConfig{
Root: "assets",
Expand Down
5 changes: 3 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import postCssPresetEnv from 'postcss-preset-env';
import ejs from 'ejs';
// import legacy from '@vitejs/plugin-legacy';
// import topLevelAwait from 'vite-plugin-top-level-await';
// import { getAppConfig } from './build/config';
import { getAppConfig } from './build/config';
import pkg from './package.json';

const appConfig = getAppConfig();
const SVGElement = fs.readFileSync('./public/icons/iconpark.tpl', 'utf-8');
const proxyHost = '127.0.0.1:9000';

Expand Down Expand Up @@ -41,7 +42,7 @@ export default defineConfig({
plugins: [
react(),
// topLevelAwait(),
htmlPlugin(),
htmlPlugin({ appInstance: appConfig.AppInstance || 'single' }),
// legacy({
// targets: ['chrome >= 87', 'safari >= 14', 'firefox >= 78'],
// polyfills: ['es.promise.finally', 'es/map', 'es/set', 'es/array'],
Expand Down