Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Caxa using current working directory instead of TMP dir for Express static serving #82

Closed
aaronsantiago opened this issue Sep 26, 2023 · 1 comment

Comments

@aaronsantiago
Copy link

Reading through some other issues on the repo it seems like this should have worked:

app.use(express.static('./public'));

However, I am finding that this attempts to serve the public folder in the directory the executable is run from. The workaround I am using for this is incredibly hacky:

import { URL } from 'url';
const __dirname = new URL('.', import.meta.url).pathname;

app.use(express.static(path.join(__dirname.slice(1), './public')));

This now behaves as I expected and serves the public folder that was packed into the executable.

Is there a more sane way to do this or a way to better understand why express isn't playing nice with caxa?

@leafac
Copy link
Owner

leafac commented Nov 21, 2023

Hi @aaronsantiago,

Thanks for considering using caxa. Perhaps there could be more elegant ways of expressing this idea, but I think that the proper solution to the issue that you bring up really is to make the path relative to the source file, instead of relative to the working directory from which your server was run. This isn’t necessary a concern having to do with caxa—the same issue would arise if you ran your server from a different directory: node path-to-application/index.mjs.

In any case, I’ve been thinking about the broad strategy employed by caxa and concluded that there is a better way to solve the problem.

It’s a different enough approach that I think it deserves a new name, and it’s part of a bigger toolset that I’m building, which I call Radically Straightforward · Package.

I’m deprecating caxa and archiving this repository. I invite you to continue the conversation in Radically Straightforward’s issues.

Best.

@leafac leafac closed this as completed Nov 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants