这是indexloc提供的服务,不要输入任何密码
Skip to content
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
12 changes: 10 additions & 2 deletions console/src/Globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const globals = {
? 'server'
: window.__env.consoleMode,
urlPrefix: checkExtraSlashes(window.__env.urlPrefix),
consolePath: window.__env.consolePath,
};

// set defaults
Expand Down Expand Up @@ -63,8 +64,15 @@ if (

if (globals.consoleMode === SERVER_CONSOLE_MODE) {
if (globals.nodeEnv !== 'development') {
const windowUrl = window.location.protocol + '//' + window.location.host;
globals.dataApiUrl = windowUrl;
const safeCurrentUrl = checkExtraSlashes(window.location.href);
globals.dataApiUrl = safeCurrentUrl.slice(
0,
safeCurrentUrl.lastIndexOf(window.__env.consolePath)
);
const currentPath = checkExtraSlashes(window.location.pathname);
globals.urlPrefix =
currentPath.slice(0, currentPath.lastIndexOf(window.__env.consolePath)) +
'/console';
}
/*
* Require the exact usecase
Expand Down
44 changes: 27 additions & 17 deletions server/src-lib/Hasura/Server/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ isAccessKeySet :: AuthMode -> T.Text
isAccessKeySet AMNoAuth = "false"
isAccessKeySet _ = "true"

mkConsoleHTML :: AuthMode -> IO T.Text
mkConsoleHTML authMode =
bool (initErrExit errMsg) (return res) (null errs)
mkConsoleHTML :: T.Text -> AuthMode -> Either String T.Text
mkConsoleHTML path authMode =
bool (Left errMsg) (Right res) $ null errs
where
(errs, res) = M.checkedSubstitute consoleTmplt $
object [ "version" .= consoleVersion
, "isAccessKeySet" .= isAccessKeySet authMode
, "consolePath" .= consolePath
]
errMsg = "Fatal Error : console template rendering failed"
++ show errs
consolePath = case path of
"" -> "/console"
r -> "/console/" <> r

errMsg = "console template rendering failed: " ++ show errs

data ServerCtx
= ServerCtx
Expand Down Expand Up @@ -304,10 +308,7 @@ httpApp mRootDir corsCfg serverCtx enableConsole = do
middleware $ corsMiddleware (mkDefaultCorsPolicy $ ccDomain corsCfg)

-- API Console and Root Dir
if enableConsole then do
consoleHTML <- lift $ mkConsoleHTML $ scAuthMode serverCtx
serveApiConsole consoleHTML
else maybe (return ()) (middleware . MS.staticPolicy . MS.addBase) mRootDir
bool serveRootDir serveApiConsole enableConsole

get "v1/version" $ do
uncurry setHeader jsonHeader
Expand Down Expand Up @@ -339,11 +340,7 @@ httpApp mRootDir corsCfg serverCtx enableConsole = do

hookAny GET $ \_ -> do
let qErr = err404 NotFound "resource does not exist"
req <- request
reqBody <- liftIO $ strictRequestBody req
logError Nothing req reqBody serverCtx qErr
uncurry setHeader jsonHeader
lazyBytes $ encode qErr
raiseGenericApiError qErr

where
tmpltGetOrDeleteH tmpltName = do
Expand All @@ -365,6 +362,19 @@ httpApp mRootDir corsCfg serverCtx enableConsole = do
v1QueryHandler $ RQExecuteQueryTemplate $
ExecQueryTemplate (TQueryName tmpltName) tmpltArgs

serveApiConsole htmlFile = do
get root $ redirect "/console"
get ("console" <//> wildcard) $ const $ html htmlFile
raiseGenericApiError qErr = do
req <- request
reqBody <- liftIO $ strictRequestBody req
logError Nothing req reqBody serverCtx qErr
uncurry setHeader jsonHeader
setStatus $ qeStatus qErr
lazyBytes $ encode qErr

serveRootDir =
maybe (return ()) (middleware . MS.staticPolicy . MS.addBase) mRootDir

serveApiConsole = do
get root $ redirect "console"
get ("console" <//> wildcard) $ \path ->
either (raiseGenericApiError . err500 Unexpected . T.pack) html $
mkConsoleHTML path $ scAuthMode serverCtx
1 change: 1 addition & 0 deletions server/src-rsr/console.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
window.__env = {
consoleMode: "server",
urlPrefix: "/console",
consolePath: "{{consolePath}}",
isAccessKeySet: {{isAccessKeySet}}
};
</script>
Expand Down