0.1.12 • Published 2 months ago

@marko/run-adapter-node v0.1.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Preview and deploy @marko/run apps on Connect-style servers

Intallation

npm install @marko/run-adapter-node

Usage

In your application's Vite config file (eg. vite.config.js), import and register this adapter with the @marko/run Vite plugin:

import { defineConfig } from "vite";
import marko from "@marko/run/vite";
import nodeAdapter from "@marko/run-adapter-node";

export default defineConfig({
  plugins: [
    marko({
      adapter: nodeAdapter()
    })
  ]
});

Middleware

This package provides two different middlwares. Both middleware handle converting Connect-style requests to WHATWG requests and similarly writing WHATWG responses back to the Connect response.

Router Middleware

This middleware fully handles requests that match a route.

// my-app-server.ts
import express from 'express'
import { routerMiddleware } from "@marko/run-adapter-node/middleware";

express()
  .use("/assets", express.static("assets"))
  .use(routerMiddleware()) // register the router middleware
  .listen(8080);

Match Middleware

This middleware attaches the matched route onto the request object where it can be invoked later. Along with an invoke function, the object will contain the route's meta data. This is useful if you have other middleware that need to run between finding a match and invoking the route.

// my-app-server.ts
import express from 'express'
import { matchMiddleware } from "@marko/run-adapter-node/middleware";

express()
  .use("/assets", express.static("assets"))
  .use(matchMiddleware()) // register the match middlware
  // ...other middleware here
  .use((req, res, next) => {
    // `req.route` will be populated if the match middlware found a route
    if (req.route) {
      // do something with `req.route.config` which will contain the route's meta data
    }
    next();
  })
  .use((req, res, next) => {
    if (req.route) {
      // finally invoke the route handler
      req.route.invoke(req, res, next)
    } else {
      next();
    }
  })
  .listen(8080);

Build and Dev

For now, check out the examples directory for more info.

0.1.12

2 months ago

0.1.10

6 months ago

0.1.11

6 months ago

0.1.8

7 months ago

0.1.7

7 months ago

0.1.9

6 months ago

0.1.6

9 months ago

0.1.4

1 year ago

0.1.5

12 months ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.1-beta3

1 year ago

0.1.3

1 year ago

0.0.1-beta4

1 year ago

0.0.1-beta2

1 year ago

0.0.1-beta1

1 year ago