Skip to content

Commit

Permalink
wip(frontend): validate yaml loading
Browse files Browse the repository at this point in the history
make sure auth is also included in the proxy config

Signed-off-by: Santiago Jimenez Giraldo <[email protected]>
  • Loading branch information
sago2k8 committed Oct 16, 2024
1 parent 4b200b0 commit b231dfb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 59 deletions.
112 changes: 58 additions & 54 deletions frontend/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,96 +5,100 @@ import { pluginSvgr } from '@rsbuild/plugin-svgr';
import { pluginSass } from '@rsbuild/plugin-sass';
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
import MonacoEditorWebpackPlugin from 'monaco-editor-webpack-plugin';
// import MonacoEditorWebpackPlugin from 'monaco-editor-webpack-plugin'

import moduleFederationConfig from './module-federation';

const { publicVars } = loadEnv({ prefixes: ['REACT_APP_'] });

export default defineConfig({
plugins: [
pluginReact({
reactRefreshOptions: {
forceEnable: true,
},
}),
pluginSvgr({ mixedImport: true }),
pluginSass(),
pluginReact({
reactRefreshOptions: {
forceEnable: true,
},
}),
pluginSvgr({ mixedImport: true }),
pluginSass(),
],
moduleFederation: {
options: moduleFederationConfig,
options: moduleFederationConfig,
},
dev: {
hmr: true,
hmr: true,
},
html: {
template: './public/index.html',
templateParameters: {
REACT_APP_ENABLED_FEATURES: process.env.REACT_APP_ENABLED_FEATURES,
REACT_APP_CONSOLE_GIT_SHA: process.env.REACT_APP_CONSOLE_GIT_SHA,
REACT_APP_CONSOLE_PLATFORM_VERSION: process.env.REACT_APP_CONSOLE_PLATFORM_VERSION,
REACT_APP_CONSOLE_GIT_REF: process.env.REACT_APP_CONSOLE_GIT_REF,
REACT_APP_BUSINESS: process.env.REACT_APP_BUSINESS,
REACT_APP_BUILD_TIMESTAMP: process.env.REACT_APP_BUILD_TIMESTAMP,
REACT_APP_DEV_HINT: process.env.REACT_APP_DEV_HINT,
},
template: './public/index.html',
templateParameters: {
REACT_APP_ENABLED_FEATURES: process.env.REACT_APP_ENABLED_FEATURES,
REACT_APP_CONSOLE_GIT_SHA: process.env.REACT_APP_CONSOLE_GIT_SHA,
REACT_APP_CONSOLE_PLATFORM_VERSION: process.env.REACT_APP_CONSOLE_PLATFORM_VERSION,
REACT_APP_CONSOLE_GIT_REF: process.env.REACT_APP_CONSOLE_GIT_REF,
REACT_APP_BUSINESS: process.env.REACT_APP_BUSINESS,
REACT_APP_BUILD_TIMESTAMP: process.env.REACT_APP_BUILD_TIMESTAMP,
REACT_APP_DEV_HINT: process.env.REACT_APP_DEV_HINT,
},
},
server: {
htmlFallback: 'index',
htmlFallback: 'index',
proxy: {
context: ['/api', '/redpanda.api'],
target: 'http://localhost:9090',
},
context: ['/api', '/redpanda.api', '/auth'],
target: 'http://localhost:9090',
},
},
source: {
define: publicVars,
decorators: {
version: 'legacy',
}
define: publicVars,
decorators: {
version: 'legacy',
},
},
output: {
distPath: {
root: 'build',
},
distPath: {
root: 'build',
},
},
tools: {
rspack: (config, { appendPlugins }) => {
rspack: (config, { appendPlugins }) => {
config.resolve ||= {};
config.resolve.alias ||= {};
config.output ||= {};
/* resolve symlinks so the proto generate code can be built. */
config.resolve.symlinks = false;

config.output.publicPath = 'auto';
config.output.globalObject = 'self';
config.output.filename = '[name].bundle.js';

const plugins = [
new NodePolyfillPlugin({
additionalAliases: ['process'],
}),
new MonacoEditorWebpackPlugin({
languages: ['json', 'yaml', 'javascript', 'typescript', 'protobuf'],
customLanguages: [
{
label: 'yaml',
entry: 'monaco-yaml',
worker: {
id: 'monaco-yaml/yamlWorker',
entry: 'monaco-yaml/yaml.worker'
}
}
]
}),
]
// new MonacoEditorWebpackPlugin({
// languages: ['json', 'yaml', 'javascript', 'typescript', 'protobuf'],
// customLanguages: [
// {
// label: 'yaml',
// entry: 'monaco-yaml',
// worker: {
// id: 'monaco-yaml/yamlWorker',
// entry: 'monaco-yaml/yaml.worker',
// },
// },
// ],
// }),
];

if (process.env.RSDOCTOR) {
plugins.push(new RsdoctorRspackPlugin({
supports: {
/**
* @see https://rsdoctor.dev/config/options/options#generatetilegraph
*/
generateTileGraph: true,
}
}));
plugins.push(
new RsdoctorRspackPlugin({
supports: {
/**
* @see https://rsdoctor.dev/config/options/options#generatetilegraph
*/
generateTileGraph: true,
},
})
);
}

appendPlugins(plugins);
Expand Down
24 changes: 19 additions & 5 deletions frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,32 @@ export const setup = memoizeOne((setupArgs: SetConfigArguments) => {

// Ensure yaml workers are being loaded locally as well
loader.init().then(async (monaco) => {
window.MonacoEnvironment = {
// eslint-disable-next-line no-restricted-globals
self.MonacoEnvironment = {
getWorker(moduleId, label) {
console.debug(`window.MonacoEnvironment.getWorker looking for moduleId ${moduleId} label ${label}`);

switch (label) {
case 'editorWorkerService':
return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker', import.meta.url));
case 'json':
return new Worker(new URL('monaco-editor/esm/vs/language/json/json.worker', import.meta.url));
case 'typescript':
case 'javascript':
return new Worker(new URL('monaco-editor/esm/vs/language/typescript/ts.worker', import.meta.url));
case 'yaml':
return new Worker(new URL('monaco-yaml/yaml.worker', import.meta.url));

default:
throw new Error(`Unknown label ${label}`);
return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker', import.meta.url));
}

// switch (label) {
// case 'editorWorkerService':
// return new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker', import.meta.url));
// case 'yaml':
// return new Worker(new URL('monaco-yaml/yaml.worker', import.meta.url));
//
// default:
// throw new Error(`Unknown label ${label}`);
// }
},
};

Expand Down

0 comments on commit b231dfb

Please sign in to comment.