Skip to content

feature/grouping-static-routes #177

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 34 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,40 @@ export default function entrypoint(options = {}) {
);

// Add yaml entries for all files outside _app directory, such as favicons
const additionalClientAssets = clientFiles
.filter((file) => !file.startsWith("_app/"))
.map((file) => ({
url: `/${file}`,
// eslint-disable-next-line camelcase
static_files: join("storage", file).replaceAll("\\", "/"),
upload: join("storage", file).replaceAll("\\", "/"),
secure: "always",
}));
const groupedFiles = {};
const additionalClientAssets = [];
// Group files by the first directory in their path
clientFiles.filter((file) => !file.startsWith("_app/")).forEach(path => {
if (path.includes('/')) {
const parts = path.split('/');
const firstDir = parts[0]; // The first directory in the path

if (!groupedFiles[firstDir]) {
groupedFiles[firstDir] = [];
}
groupedFiles[firstDir].push(path);
} else {
const config = {
url: `/${path}`,
static_files: join("storage", path).replaceAll("\\", "/"),
upload: join("storage", path).replaceAll("\\", "/"),
secure: "always",
}
additionalClientAssets.push(config);
}
});

// Generate configuration objects
Object.keys(groupedFiles).forEach(dir => {
const regexBase = dir + '/(.+/)?([^/]+)'; // Create regex for capturing everything under the directory
const config = {
url: `/${regexBase}`,
static_files: `storage/${dir}/\\1\\2`,
upload: `storage/${regexBase}`,
secure: 'always',
};
additionalClientAssets.push(config);
});

// Load existing app.yaml if it exists
let yaml = {};
Expand Down