|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const wdm = require("webpack-dev-middleware"); |
| 4 | +const { Hono } = require("hono"); |
| 5 | +const { serve } = require("@hono/node-server"); |
| 6 | +// eslint-disable-next-line import/extensions, import/no-unresolved |
| 7 | +const { serveStatic } = require("@hono/node-server/serve-static"); |
| 8 | +const { setup } = require("../../util"); |
| 9 | + |
| 10 | +// our setup function adds behind-the-scenes bits to the config that all of our |
| 11 | +// examples need |
| 12 | +module.exports = setup({ |
| 13 | + context: __dirname, |
| 14 | + entry: "./app.js", |
| 15 | + devServer: { |
| 16 | + // WARNING: |
| 17 | + // |
| 18 | + // You always need to set up middlewares which you required for your app, |
| 19 | + // built-in middlewares (like `history-api-fallback`/etc) doesn't work by default with `hono` |
| 20 | + setupMiddlewares: (_, devServer) => [ |
| 21 | + { |
| 22 | + name: "webpack-dev-middleware", |
| 23 | + middleware: wdm.honoWrapper(devServer.compiler), |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "static", |
| 27 | + path: "/.assets/*", |
| 28 | + middleware: serveStatic({ |
| 29 | + root: "../../.assets", |
| 30 | + rewriteRequestPath: (item) => item.replace(/^\/\.assets\//, "/"), |
| 31 | + }), |
| 32 | + }, |
| 33 | + ], |
| 34 | + app: () => new Hono(), |
| 35 | + server: (_, app) => |
| 36 | + serve({ |
| 37 | + fetch: app.fetch, |
| 38 | + // |
| 39 | + // Uncomment for `https` |
| 40 | + // createServer: require('node:https').createServer, |
| 41 | + // serverOptions: { |
| 42 | + // key: fs.readFileSync("./ssl/localhost-privkey.pem"), |
| 43 | + // cert: fs.readFileSync("./ssl/localhost-cert.pem"), |
| 44 | + // }, |
| 45 | + // |
| 46 | + // Uncomment for `http2` |
| 47 | + // createServer: require("node:http2").createSecureServer, |
| 48 | + // serverOptions: { |
| 49 | + // allowHTTP1: true, |
| 50 | + // key: require("fs").readFileSync("./ssl/localhost-privkey.pem"), |
| 51 | + // cert: require("fs").readFileSync("./ssl/localhost-cert.pem"), |
| 52 | + // }, |
| 53 | + }), |
| 54 | + }, |
| 55 | +}); |
0 commit comments