Server
Set up a server for your site.
Lume includes a Server
class used to run a HTTP server. You can use this class to start your own server, for example, to serve the static files in Deno Deploy. Let's see a basic example of a server:
import Server from "lume/core/server.ts";
const server = new Server({
port: 8000,
root: `${Deno.cwd()}/_site`,
});
server.start();
console.log("Listening on http://localhost:8000");
This code starts a local server on port 8000
and serves static files from the _site
folder.
Events
You can assign event listeners to the server:
server.addEventListener("start", () => {
console.log("Server started successfully");
});
Middleware
To customize how the server handles requests and responses, there's a simple middleware system with the following signature:
server.use(async (request, next) => {
// Here you can modify the request before being passed to next middlewares
const response = await next(request);
// Here you can modify the response before being returned to the previous middleware
return response;
});
The request and response objects are standard Request
and Response
classes, no magic here.
Lume provides some middleware for common use cases:
import Server from "lume/core/server.ts";
import expires from "lume/middlewares/expires.ts";
const server = new Server();
server.use(expires());
server.start();
Go to Plugins/middleware for a list of all middleware plugins provided by Lume.