UNPKG

intlayer-editor

Version:

Integrate the Intlayer visual editor into your Intlayer projects, enabling CMS-like content management with multilingual support.

103 lines (102 loc) 4.66 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var import_config = require("@intlayer/config"); var import_config2 = require('./routes/config.routes.cjs'); var import_dictionary = require('./routes/dictionary.routes.cjs'); var import_checkPortAvailability = require('./utils/checkPortAvailability.cjs'); var import_compression = __toESM(require("compression"), 1); var import_cookie_parser = __toESM(require("cookie-parser"), 1); var import_cors = __toESM(require("cors"), 1); var import_express = __toESM(require("express"), 1); var import_express_intlayer = require("express-intlayer"); var import_helmet = __toESM(require("helmet"), 1); var import_mime = __toESM(require("mime"), 1); var import_node_fs = require("node:fs"); var import_node_path = __toESM(require("node:path"), 1); var import_node_url = require("node:url"); const import_meta = {}; const __dirname = (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url)); const envFileOptions = { env: process.env.NODE_ENV, envFile: process.env.ENV_FILE }; const packageJson = JSON.parse( (0, import_node_fs.readFileSync)((0, import_node_path.resolve)(__dirname, "../../package.json"), "utf8") ); const app = (0, import_express.default)(); app.use((0, import_express_intlayer.intlayer)()); const FALLBACK_PORT = 8e3; const config = (0, import_config.getConfiguration)(envFileOptions); const port = config.editor.port ?? FALLBACK_PORT; const clientDistPath = (0, import_node_path.resolve)(__dirname, "../../client/dist"); const corsOptions = { origin: "*", credentials: true }; const startServer = async (app2) => { const isPortAvailable = await (0, import_checkPortAvailability.checkPortAvailability)(port); if (!isPortAvailable) { console.error(`\x1B[1;31mError: Port ${port} is already in use.\x1B[0m`); process.exit(255); } app2.disable("x-powered-by"); app2.use( (0, import_helmet.default)({ contentSecurityPolicy: false }) ); app2.use((0, import_cors.default)(corsOptions)); app2.use((0, import_compression.default)()); app2.use(import_express.default.json()); app2.use((0, import_cookie_parser.default)()); app2.use(import_express.default.urlencoded({ extended: true })); app2.use("/api/dictionary", import_dictionary.dictionaryRouter); app2.use("/api/config", import_config2.configurationRouter); app2.use(import_express.default.static(clientDistPath)); app2.get(/(.*)/, (req, res) => { const requestedPath = import_node_path.default.join(clientDistPath, req.url); if ((0, import_node_fs.existsSync)(requestedPath) && (0, import_node_fs.lstatSync)(requestedPath).isFile()) { const mimeType = import_mime.default.getType(requestedPath) ?? "application/octet-stream"; res.setHeader("Content-Type", mimeType); res.sendFile(requestedPath); } else { res.sendFile((0, import_node_path.resolve)(clientDistPath, "index.html")); } }); app2.listen(port, () => { const dotEnvFilePath = (0, import_config.getEnvFilePath)( envFileOptions.env, envFileOptions.envFile ); console.log(` \x1B[1;90mINTLAYER v${packageJson.version}\x1B[0m Editor running at: \x1B[90mhttp://localhost:${port}\x1B[0m - Watching application at: ${config.editor.applicationURL === "" ? "-" : `\x1B[90m${config.editor.applicationURL}\x1B[0m`} - Access key: ${config.editor.clientId ?? "-"} - Environment: ${dotEnvFilePath ?? "-"} `); }); }; startServer(app); //# sourceMappingURL=index.cjs.map