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

fix: Improve Static Server Reliability #11

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lilnasy
Copy link

@lilnasy lilnasy commented Dec 23, 2024

Changes

  • Closes Cannot serve .webp image in mdx #4
  • Astro SSR manifest is not exactly public API. If it works it works, but if it doesn't we should use something else.
  • In this case, optimized images are not included in the "assets" list, which the adapter relied upon.
  • Updated the logic to read the client directory on server boot and use the found files instead of the assets list in the SSR manifest.

image

package/package.json Outdated Show resolved Hide resolved
package/src/index.ts Outdated Show resolved Hide resolved
package/src/index.ts Outdated Show resolved Hide resolved
package/src/server/index.ts Outdated Show resolved Hide resolved
@@ -106,3 +127,44 @@ function handler(
});
};
}

async function getStaticAssets(clientDir: string) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async function getStaticAssets(clientDir: string) {
async function getStaticAssets(clientDir: string): Promise<Set<string>> {

return client;
}

function prependForwardSlash(pth: string) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function prependForwardSlash(pth: string) {
function prependForwardSlash(pth: string): string {

return pth.startsWith('/') ? pth : '/' + pth;
}

function appendForwardSlash(pth: string) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function appendForwardSlash(pth: string) {
function appendForwardSlash(pth: string): string {

*
* Copyright of withastro/adapters contributors, Reproduced under MIT License
*/
function resolveClientDir(options: InternalOptions) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function resolveClientDir(options: InternalOptions) {
function resolveClientDir(options: InternalOptions): string {

const serverURLRaw = new URL(options.server);
const rel = path.relative(url.fileURLToPath(serverURLRaw), url.fileURLToPath(clientURLRaw));

// walk up the parent folders until you find the one that is the root of the server entry folder. This is how we find the client folder relatively.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// walk up the parent folders until you find the one that is the root of the server entry folder. This is how we find the client folder relatively.
// Walk up the parent folders until you find the one that is the root of the server entry folder. This is how we find the client folder relatively.

package/src/types.ts Outdated Show resolved Hide resolved
@NuroDev
Copy link
Owner

NuroDev commented Dec 23, 2024

It also seems you have based this branch off of your branch used for #10 so the 2 you've put 2 PR's into 1.

@lilnasy lilnasy marked this pull request as draft January 18, 2025 16:13
@lilnasy
Copy link
Author

lilnasy commented Jan 18, 2025

Marking as draft because it depends on types being corrected in #10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot serve .webp image in mdx
2 participants