lumeland / lume

🔥 Static site generator for Deno 🦕
https://lume.land
MIT License
1.83k stars 83 forks source link

Allow to configure the root directory of the server #382

Closed boeckMt closed 1 year ago

boeckMt commented 1 year ago

Enter your suggestions in details:

It would be nice if a user could set the server root in the configuration Server options to serve static files that shouldn't be copied on every build.

That could be done somewhere here https://github.com/lumeland/lume/blob/73200d261f3bda81c04fb820d71e118aaca8060a/cli/build.ts#L97


Another nice option would be to allow swapping the server instance e.g.

...
import Server from "https:/deno.land/x/lume/core/server.ts";

const server = new Server({
  port: 8000,
  root: `${Deno.cwd()}/dist`,
});

server.start();

const site = lume({
  src: "./src",
  dest: "./dist/build",
  emptyDest: false,
  server: server
});

My use case is that I have many images that are in another directory and I don't want to copy them (like Copy static files) to the dist folder to prevent duplication and unnecessary work.

As a workaround I tried using a second server and redirects but unfortunately that don't work.

const server = new Server({
  port: 3001,
  root: `${Deno.cwd()}/dist`,
});

server.addEventListener("start", (event) => {
  console.log(`Listening on http://localhost:${server.options.port}`);
});

server.start();

const site = lume({
  src: "./src",
  dest: "./dist/build",
  emptyDest: false,
  location: new URL("https://activations.zki.dlr.de"),
  server: {
    port: 3000,
    middlewares: [
      redirects: {
        "http://localhost:3000/portaldata/": "http://localhost:3001/portaldata/",
      }
    ],
  },
});
oscarotero commented 1 year ago

Probably this could be done with a new a middleware. Something like this:

const server = new Server({
  port: 3000,
  root: `${Deno.cwd()}/dist`,
});

server.use(staticFolder({
  root: "/path/to/another/folder"
});
oscarotero commented 1 year ago

@boeckMt I have created this middleware. You can use it as following:

import lume from "lume/mod.ts";
import staticFolder from "https://raw.githubusercontent.com/lumeland/experimental-plugins/main/static_folder/mod.ts";

const site = lume({
  server: {
      middlewares: [
        staticFolder({
          root: Deno.cwd() + "/path/the/folder",
        })
      ]
    },
});

export default site;

Let me know if it works for you.

boeckMt commented 1 year ago

@oscarotero tanks for the fast response and creation of this middleware! It works perfectly :)


I'm currently trying to migrate a site from metalsmith which, by the way, works very well.

oscarotero commented 1 year ago

Great! I think this middleware may be useful to other users, so I'll move it to the official Lume repository.