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

Azure functions We are not awaiting readAsset #669

Closed
mcremer-able opened this issue Nov 16, 2022 · 2 comments
Closed

Azure functions We are not awaiting readAsset #669

mcremer-able opened this issue Nov 16, 2022 · 2 comments
Labels

Comments

@mcremer-able
Copy link
Contributor

Environment

Nuxi 3.0.0-rc.13 19:19:41
Nuxt 3.0.0-rc.13 with Nitro 0.6.1
node v16.03

Reproduction

Describe the bug

In

export function readAsset (id) {

We are returning a promise to read a file and not the file itself.
so in
return readAsset(id)

We return a Promise as well.
This causes static assets not to work.
This might me specific to the azure-function preset

This causes assets to not to show up correctly or get downright rejected by the sanitizer for the incorrect file size
grafik

Additional context

If I go in to the compiled js files and modify the runtime/static.ts file, then it does work again.
I make the handler async and await the read operation.

const _f4b49z = eventHandler(async (event) => {
  if (event.req.method && !METHODS.includes(event.req.method)) {
    return;
  }
  let id = decodeURIComponent(withLeadingSlash(withoutTrailingSlash(parseURL(event.req.url).pathname)));
  let asset;
  const encodingHeader = String(event.req.headers["accept-encoding"] || "");
  const encodings = encodingHeader.split(",").map((e) => EncodingMap[e.trim()]).filter(Boolean).sort().concat([""]);
  if (encodings.length > 1) {
    event.res.setHeader("Vary", "Accept-Encoding");
  }
  for (const encoding of encodings) {
    for (const _id of [id + encoding, joinURL(id, "index.html" + encoding)]) {
      const _asset = getAsset(_id);
      if (_asset) {
        asset = _asset;
        id = _id;
        break;
      }
    }
  }
  if (!asset) {
    if (isPublicAssetURL(id)) {
      throw createError({
        statusMessage: "Cannot find static asset " + id,
        statusCode: 404
      });
    }
    return;
  }
  const ifNotMatch = event.req.headers["if-none-match"] === asset.etag;
  if (ifNotMatch) {
    event.res.statusCode = 304;
    event.res.end();
    return;
  }
  const ifModifiedSinceH = event.req.headers["if-modified-since"];
  if (ifModifiedSinceH && asset.mtime) {
    if (new Date(ifModifiedSinceH) >= new Date(asset.mtime)) {
      event.res.statusCode = 304;
      event.res.end();
      return;
    }
  }
  if (asset.type && !event.res.getHeader("Content-Type")) {
    event.res.setHeader("Content-Type", asset.type);
  }
  if (asset.etag && !event.res.getHeader("ETag")) {
    event.res.setHeader("ETag", asset.etag);
  }
  if (asset.mtime && !event.res.getHeader("Last-Modified")) {
    event.res.setHeader("Last-Modified", asset.mtime);
  }
  if (asset.encoding && !event.res.getHeader("Content-Encoding")) {
    event.res.setHeader("Content-Encoding", asset.encoding);
  }
  if (asset.size && !event.res.getHeader("Content-Length")) {
    event.res.setHeader("Content-Length", asset.size);
  }
  return await readAsset(id);
});

Logs

No response

Copy link
Member

@mcremer-able Could you provide a reproduction please ?

@danielroe
Copy link
Member

I think we can close this as there is no reproduction. If you are still experiencing this, would you provide a reproduction? 🙏

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants