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

Serve multiple directories #192

Open
viveleroi opened this issue Apr 10, 2017 · 6 comments
Open

Serve multiple directories #192

viveleroi opened this issue Apr 10, 2017 · 6 comments

Comments

@viveleroi
Copy link

I'd like to serve static files in two directories - one with my html, one with some compiled css that gets distributed with an npm package. I don't see a way to do this?

@fenwick67
Copy link

fenwick67 commented May 15, 2017

If you are using Express you should be able to just install two middlewares, one for each directory you want to serve. It will fall through the first middleware if the file isn't found in that directory, and it will move down the middleware chain.

app.use(ecstatic({ root: __dirname + '/compiled-css', handleError: false }));
app.use(ecstatic({ root: __dirname + '/public', handleError: false }));

@viveleroi
Copy link
Author

Thanks, but we specifically wanted a light-weight http server and chose not to use express.

@viveleroi
Copy link
Author

Thanks, but we specifically wanted a light-weight http server and chose not to use express.

@viveleroi viveleroi reopened this May 15, 2017
@jfhbrook
Copy link
Owner

jfhbrook commented May 15, 2017

You can do the same trick, roughly, but using stock http, something like:

http.createServer((req, res) => {
  ecstaticFirstDir(req, res, (err) => {
    if (shouldFail(res, err)) {
      return fail(res, error);
    }

    ecstaticSecondDir(req, res);
  });
})

There is no way to do this from the CLI, but if you're doing that anyway...have you considered nginx?

@viveleroi
Copy link
Author

I can try that, though seems trivial for the package to add support for multiple dirs. This has to be purely-node driven based on our use case.

@jfhbrook
Copy link
Owner

Adding support for multiple dirs in the middleware itself is probably harder than it sounds, and not a road I want to go down, especially considering more far-reaching work like what #183 entails.

Adding this to the cli might be doable...if you can convince me that your use case is common. I tend to tell people to use nginx for general purpose non-development static file hosting, since that project is much more industrial grade, properly benchmarked, has fewer bugs etc.

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