question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serve a directory of static files

See original GitHub issue

Hi, thanks for doing this @sholladay - is there a way to serve a directory of static files at a particular path with the correct response type set automatically?

The use case is to serve the web UI- e.g. the production build of a create-react-app project

In Hapi, I can do this with @hapi/inert and the directory handler it gives.

  server.route({
    method: "GET",
    path: "/app/{path*}",
    handler: {
      directory: {
        path: Path.join(__dirname, "../../client/build/"),
        listing: false,
        index: true
      }
    }
  });

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sholladaycommented, Jul 9, 2020

Deno (via TypeScript) compiles the JSX syntax to React.createElement() calls, so long as a .jsx or .tsx file extension is used. However, Deno does not provide an implementation of React, so we need to import React anywhere that JSX is used. Pogo is responsible for rendering those React calls to static HTML markup via ReactDOMServer. Or you can render them yourself and return the markup as a string, Pogo will still treat it as HTML.

I hope that clears things up! We could probably use an FAQ section with that in it. I also just noticed that the README mentions the Pika CDN, which I had to stop using due to some bugs. That needs to be updated.

1reaction
sholladaycommented, May 25, 2020

This feature should be easier to implement now because of the new router (see #29).

Previously, you would’ve had to read the filesystem and map all of the desired file names to a list of paths and then construct a list of routes based on that, which would be annoying.

Now, we have support for wildcard paths, such as /{foo*}, which will match any request that starts with /. Or /bar/{foo*}, which will match any request that starts with /bar/. You’ll probably want to use that in any route that serves a directory so that it can look up arbitrary file names from within the handler.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What exactly does 'serving static files' mean? - Stack Overflow
Static files are typically files such as scripts, CSS files, images, etc... that aren't server-generated, but must be sent to the browser when ......
Read more >
Many Options to Run a Local Static Server | by Jair Reina
You should first enter to your “project” folder in the command line doing ... You can of course use it just to serve...
Read more >
How to manage static files (e.g. images, JavaScript, CSS)
Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg . Serving the files.
Read more >
ExpressJS - Serving static files - Tutorialspoint
ExpressJS - Serving static files, Static files are files that clients download as they are from the server. Create a new directory, public....
Read more >
Serving Static Resources in Node.js - TutorialsTeacher
It is easy to serve static files using built-in middleware in Express.js called express.static. Using express.static() method, you can server static resources ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found