Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/lib/share/init.js
Views: 687
/*1IMPORTANT: to use this from packages/hub (say), it's critical that2packages/hub *also* have its own copy of next installed.3Otherwise, you'll see an error about45"Parsing error: Cannot find module 'next/babel'"67This is mentioned here, and it's maybe a bug in next?8https://www.gitmemory.com/issue/vercel/next.js/26127/8626618189*/1011const { join } = require("path");12const next = require("next");13const conf = require("../next.config");14const getLogger = require("@cocalc/backend/logger").default;1516async function init({ basePath }) {17const winston = getLogger("share-server:init");1819// dev = Whether or not to run in dev mode. This features hot module reloading,20// but navigation between pages and serving pages is much slower.21const dev = process.env.NODE_ENV != "production";2223// We do this to ensure that our config is like when24// running things directly (via npm run dev), without having25// to set the BASE_PATH env variable, which might have26// a strange impact somewhere else in CoCalc.27conf.basePath = basePath == "/" ? "" : basePath; // won't happen since is "../share".28conf.env.BASE_PATH = basePath;2930winston.info(31`creating next.js app with basePath="${basePath}", and dev=${dev}`32);33const app = next({ dev, conf, dir: join(__dirname, "..") });34const handle = app.getRequestHandler();35winston.info("preparing next.js app...");36await app.prepare();37winston.info("ready to handle next.js requests");38return (req, res) => {39winston.http("req.url %s", req.url);40handle(req, res);41};42}4344module.exports = init;454647