@grouparoo/core
Version:
The Grouparoo Core
85 lines (84 loc) • 3.77 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Next = void 0;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const actionhero_1 = require("actionhero");
class Next extends actionhero_1.Initializer {
constructor() {
super();
this.name = "next";
this.loadPriority = 1000;
this.startPriority = 899;
this.stopPriority = 101;
}
async initialize() {
actionhero_1.api.next = {
render: async (connection) => {
if (connection.type !== "web") {
throw new Error('Connections for next.js apps must be of type "web"');
}
const { req, res } = connection.rawConnection;
return actionhero_1.api.next.handle(req, res);
},
};
}
async start() {
if (actionhero_1.config.web.enabled !== true)
return;
if (!actionhero_1.config.next.enabled) {
(0, actionhero_1.log)("next disabled");
return;
}
if (actionhero_1.config.next.dev) {
(0, actionhero_1.log)("Running next in development mode...");
}
// We don't want to statically import next until we know we need it. It loads a lot and has problems in test mode
// We also don't want next to be part of grouparoo/core, but to come from the UI plugins (could be locally installed or hoisted)
const nextWithinPluginPath = path_1.default.join(actionhero_1.config.general.paths.next[0], "node_modules", "next");
const next = await Promise.resolve().then(() => __importStar(require(fs_1.default.existsSync(nextWithinPluginPath) ? nextWithinPluginPath : "next")));
const conf = await Promise.resolve().then(() => __importStar(require(path_1.default.join(actionhero_1.config.general.paths.next[0], "next.config.js"))));
actionhero_1.api.next.app = next.default({
dev: actionhero_1.config.next.dev,
quiet: actionhero_1.config.next.quiet,
dir: actionhero_1.config.general.paths.next[0],
conf,
});
actionhero_1.api.next.handle = actionhero_1.api.next.app.getRequestHandler();
await actionhero_1.api.next.app.prepare();
if (actionhero_1.config.web.enabled === true) {
actionhero_1.route.registerRoute("get", "/", "next:render", null, true);
}
}
async stop() {
if (actionhero_1.api.next.app)
await actionhero_1.api.next.app.close();
}
}
exports.Next = Next;