Skip to content

Commit

Permalink
fix: middleware work with websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Feb 28, 2024
1 parent eddcc68 commit bb6d131
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"trailingComma": "all",
"useTabs": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"plugins": ["@trivago/prettier-plugin-sort-imports", "importAttributes"],
"importOrder": [
"^(fully-react/(.*)$)|^(fully-react$)",
"<THIRD_PARTY_MODULES>",
Expand Down
40 changes: 29 additions & 11 deletions packages/vinxi/bin/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ const command = defineCommand({
description: "Stacks",
alias: "s",
},
version: {
type: "boolean",
description: "Print the versions of Vinxi core dependencies",
}
},
async run({ args }) {
const chokidar = await import("chokidar");
const { loadApp } = await import("../lib/load-app.js");
const { log, c } = await import("../lib/logger.js");
log(c.dim(c.yellow(`v${packageJson.version}`)));

if (args.version) {
await printVersions()
}

const configFile = args.config;
globalThis.MANIFEST = {};
Expand Down Expand Up @@ -196,16 +204,20 @@ const command = defineCommand({
type: "string",
description: "Server preset (default: node-server)",
},
version: {
type: "boolean",
description: "Print the versions of Vinxi core dependencies",
}
},
async run({ args }) {
const configFile = args.config;
globalThis.MANIFEST = {};
const { log, c } = await import("../lib/logger.js");
log(c.dim(c.yellow(`v${packageJson.version}`)));

let nitro = await import("nitropack/package.json", { assert: { type: "json" }});
log(c.dim(c.yellow(`Nitro: ${nitro.default.version}`)));

if (args.version) {
await printVersions()
}
const { loadApp } = await import("../lib/load-app.js");
const app = await loadApp(configFile, args);
process.env.NODE_ENV = "production";
Expand Down Expand Up @@ -481,18 +493,24 @@ const command = defineCommand({
const { log, c } = await import("../lib/logger.js");
log(c.dim(c.yellow(`v${packageJson.version}`)));

let vite = await import("vite/package.json", { assert: { type: "json" }});
log(c.dim(c.yellow(`vite v${vite.default.version}`)));

let nitro = await import("nitropack/package.json", { assert: { type: "json" }});
log(c.dim(c.yellow(`nitro v${nitro.default.version}`)));

let h3 = await import("h3/package.json", { assert: { type: "json" }});
log(c.dim(c.yellow(`h3 v${h3.default.version}`)));
await printVersions();

},
}
}),
});

async function printVersions() {
const { log, c } = await import("../lib/logger.js");

let vite = await import("vite/package.json", { assert: { type: "json" }});
log(c.dim(c.yellow(`vite v${vite.default.version}`)));

let nitro = await import("nitropack/package.json", { assert: { type: "json" }});
log(c.dim(c.yellow(`nitro v${nitro.default.version}`)));

let h3 = await import("h3/package.json", { assert: { type: "json" }});
log(c.dim(c.yellow(`h3 v${h3.default.version}`)));
}

runMain(command);
4 changes: 1 addition & 3 deletions packages/vinxi/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ const routerModePlugin = {
import middleware from "${join(config.router.root, config.router.middleware)}";
import handler from "${join(config.router.root, config.router.handler)}";
import { eventHandler } from "vinxi/http";
export default eventHandler({ onRequest: middleware.onRequest, onBeforeResponse: middleware.onBeforeResponse, handler });`;
export default eventHandler({ onRequest: middleware.onRequest, onBeforeResponse: middleware.onBeforeResponse, handler, websocket: handler.__websocket__ });`;
}
return `import handler from "${join(
config.router.root,
Expand Down Expand Up @@ -718,8 +718,6 @@ function browserBuild() {
if (env.command === "build") {
invariant(router && router.type !== "static", "Invalid router");
const { join } = await import("./path.js");
console.log(await getEntries(router));
console.log({ base: router.base });
let base = join(app.config.server.baseURL ?? "/", router.base);

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/vinxi/lib/router-dev-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ROUTER_MODE_DEV_PLUGINS = {
import middleware from "${join(router.root, router.middleware)}";
import handler from "${join(router.root, router.handler)}";
import { eventHandler } from "vinxi/http";
export default eventHandler({ onRequest: middleware.onRequest, onBeforeResponse: middleware.onBeforeResponse, handler});`;
export default eventHandler({ onRequest: middleware.onRequest, onBeforeResponse: middleware.onBeforeResponse, handler, websocket: handler.__websocket__});`;
}
return `import handler from "${join(
router.root,
Expand Down

0 comments on commit bb6d131

Please sign in to comment.