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

Deno.readDir and Deni.cwd not available when deployed #74

Closed
AndrewHeaney opened this issue Aug 9, 2021 · 3 comments
Closed

Deno.readDir and Deni.cwd not available when deployed #74

AndrewHeaney opened this issue Aug 9, 2021 · 3 comments

Comments

@AndrewHeaney
Copy link

Hi, I am creating a simple blog using pagic and oak with Deno. I can run my code fine locally using deployctl but I get these errors when the code is deployed.

[uncaught oak error]: TypeError - Deno.cwd is not a function

[uncaught oak error]: TypeError - Deno.readDir(...) is not a function or its return value is not async iterable

My code looks as follows:


const app = new Application();
const router = new Router();

router.get("/", async (ctx) => {
  let links = [];
  for await (const dirEntry of Deno.readDir("public")) {
    if (dirEntry.isFile && dirEntry.name.match("^[a-zA-Z]+.[a-zA-Z]+.html$")) {
      console.log(dirEntry);
      links.push(`<a href="${dirEntry.name}">${dirEntry.name}</a>`);
    }
  }

  ctx.response.headers.set("Content-Type", "html");
  ctx.response.body = `
    <h1>Blog</h1>
    <h5>Example blog using Deno</h5>
    <p>Posts:</p>
    ${links}
  `;
});

app.use(router.routes());

// Send static content
app.use(async (context) => {
  await context.send({
    root: `${Deno.cwd()}/public`,
  });
});

addEventListener("fetch", app.fetchEventHandler());

Any help is appreciated.

@satyarohith
Copy link
Member

Hi, @AndrewHeaney :)

Support for Deno.readDir() and Deno.cwd() (You can use import.meta.url as near replacement) is not available on Deploy yet. They should be available in a few weeks. You can refer https://deno.com/deploy/docs/runtime-api for supported APIs.

@AndrewHeaney
Copy link
Author

No problem, thank you for the response. I'll check it out when it becomes available.

@lucacasonato
Copy link
Member

Thanks for contributing by opening an issue.

This project is being archived because you can now use deno run to run your Deploy scripts locally: https://deno.com/deploy/docs/running-scripts-locally/. As such, I will close this issue.

If you have feedback about Deno Deploy, please open an issue on this repo: https://github.com/denoland/deploy_feedback

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

No branches or pull requests

3 participants