UNPKG

@rivetkit/next-js

Version:

Next.js integration for RivetKit actors and client

31 lines (29 loc) 1.23 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/mod.ts var toNextHandler = (registry, inputConfig = {}) => { inputConfig.disableDefaultServer = true; const publicUrl = _nullishCoalesce(_nullishCoalesce(process.env.NEXT_PUBLIC_SITE_URL, () => ( process.env.NEXT_PUBLIC_VERCEL_URL)), () => ( `http://127.0.0.1:${_nullishCoalesce(process.env.PORT, () => ( 3e3))}`)); inputConfig.runnerKind = "serverless"; inputConfig.runEngine = true; inputConfig.autoConfigureServerless = { url: `${publicUrl}/api/rivet/start` }; inputConfig.noWelcome = true; const { fetch } = registry.start(inputConfig); const fetchWrapper = async (request, { params }) => { const { all } = await params; const newUrl = new URL(request.url); newUrl.pathname = all.join("/"); const newReq = new Request(newUrl, request); return await fetch(newReq); }; return { GET: fetchWrapper, POST: fetchWrapper, PUT: fetchWrapper, PATCH: fetchWrapper, HEAD: fetchWrapper, OPTIONS: fetchWrapper }; }; exports.toNextHandler = toNextHandler; //# sourceMappingURL=mod.js.map