mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 08:23:12 +09:00
Limit the development server to sources and dependencies
Vite serves any file under fs.allow through /@fs/, and the default allow list is the workspace root. In a clusterio checkout that is also the usual data directory, so with --dev any client that could reach the controller could fetch config-controller.json, config-ctl.json and the database without logging in. webpack-dev-middleware only served the compiled bundles. Allow the controller, web_ui, lib and dev plugin directories and the node_modules directories Node.js would resolve their imports from. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ebedf6b3b0
commit
5c92a44e65
2 files changed
+21
-2
No files matched your search
@@ -524,7 +524,6 @@ export default class Controller {
|
|||||||
server: {
|
server: {
|
||||||
middlewareMode: true,
|
middlewareMode: true,
|
||||||
preTransformRequests: false,
|
preTransformRequests: false,
|
||||||
fs: { allow: [vite.searchForWorkspaceRoot(controllerDir), ...pluginDirs.values()] },
|
|
||||||
},
|
},
|
||||||
plugins: [webUiVite.clusterioDevPlugins(pluginDirs)],
|
plugins: [webUiVite.clusterioDevPlugins(pluginDirs)],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ const polyfills = {
|
|||||||
zlib: "browserify-zlib",
|
zlib: "browserify-zlib",
|
||||||
};
|
};
|
||||||
const webUiPackage = fileURLToPath(new URL("./package.json", import.meta.url));
|
const webUiPackage = fileURLToPath(new URL("./package.json", import.meta.url));
|
||||||
|
const libPackage = createRequire(webUiPackage).resolve("@clusterio/lib/package.json");
|
||||||
const sharedPrefix = "\0clusterio:shared/";
|
const sharedPrefix = "\0clusterio:shared/";
|
||||||
const pluginPrefix = "\0clusterio:plugin/";
|
const pluginPrefix = "\0clusterio:plugin/";
|
||||||
|
|
||||||
@@ -83,6 +84,19 @@ async function findFile(dir, candidates) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// node_modules directories Node.js would search for packages imported from dir.
|
||||||
|
function nodeModulesDirs(dir) {
|
||||||
|
const dirs = [];
|
||||||
|
for (let current = dir; ; current = path.dirname(current)) {
|
||||||
|
if (path.basename(current) !== "node_modules") {
|
||||||
|
dirs.push(path.join(current, "node_modules"));
|
||||||
|
}
|
||||||
|
if (current === path.dirname(current)) {
|
||||||
|
return dirs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function chunkName(name) {
|
function chunkName(name) {
|
||||||
return name.replace(/^@/, "").replace(/[/]/g, "_");
|
return name.replace(/^@/, "").replace(/[/]/g, "_");
|
||||||
}
|
}
|
||||||
@@ -292,8 +306,14 @@ export function clusterioApp({ entry }) {
|
|||||||
export function clusterioDevPlugins(pluginDirs) {
|
export function clusterioDevPlugins(pluginDirs) {
|
||||||
return {
|
return {
|
||||||
name: "clusterio:dev-plugins",
|
name: "clusterio:dev-plugins",
|
||||||
config() {
|
config(config) {
|
||||||
|
const root = path.resolve(config.root ?? process.cwd());
|
||||||
|
const sources = [root, path.dirname(webUiPackage), path.dirname(libPackage), ...pluginDirs.values()];
|
||||||
return {
|
return {
|
||||||
|
server: {
|
||||||
|
// Vite's default is the workspace root, which may be the data directory.
|
||||||
|
fs: { allow: [...sources, ...sources.flatMap(nodeModulesDirs)] },
|
||||||
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
entries: [...pluginDirs.values()].flatMap(
|
entries: [...pluginDirs.values()].flatMap(
|
||||||
dir => [`${dir}/index.{ts,js}`, `${dir}/web/**/*.{ts,tsx,js,jsx}`]
|
dir => [`${dir}/index.{ts,js}`, `${dir}/web/**/*.{ts,tsx,js,jsx}`]
|
||||||
|
|||||||
Reference in new issue
Block a user