Skip to content

Change how we figure out which directory should be served as static #62

@jacobwod

Description

@jacobwod

Currently we use __dirname (which returns the path of server.js) as starting point in finding our way to /public.

const root = path.normalize(`${__dirname}/../..`);

app.use(Express.static(`${root}/public`));

There are two issues with this scenario:

  1. It doesn't work after we've compiled the source (in the resulting /dist, /public is just one directory up from server.js, not two)
  2. The path is not OS-agnostic

I propose a solution that uses process.cwd() instead. Given that we launch the process from /, it's an easy task to find /public:

app.use(Express.static(path.join(process.cwd(), "public")));

This works well both with in dev and production and is OS-agnostic as we compile the path using path.join(). Furthermore, in combination with #61, the const root can be entirely removed as it's not used anymore.

Let me know if I should prepare the PR for this one too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions