intlayer-editor 9.6.0 → 9.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/intlayer-editor.mjs +29 -7
- package/client/dist/assets/CodeBlockShiki-BaQlmvsF.js +2 -0
- package/client/dist/assets/MarkDownRender-CufSxUcK.js +25 -0
- package/client/dist/assets/MarkDownRender-HV9SKc56.js +1 -0
- package/client/dist/assets/MarkdownEditor-BSbSD-tQ.js +174 -0
- package/client/dist/assets/{astro-JHDYjn39.js → astro-BZ97kZFP.js} +1 -1
- package/client/dist/assets/codeTransformer-pmm6yJGh.js +9 -0
- package/client/dist/assets/compat-BqYysBkt.js +1 -0
- package/client/dist/assets/css-BGIxQoYs.js +1 -0
- package/client/dist/assets/css-DgaLhXQH.js +1 -0
- package/client/dist/assets/dist-VBWB9uC8.js +11 -0
- package/client/dist/assets/extractUrlFromSitemap-Chj1JVpo.js +1 -0
- package/client/dist/assets/html-BCy9P6D2.js +1 -0
- package/client/dist/assets/{html-B2cKP6UN.js → html-DSw1lh5G.js} +1 -1
- package/client/dist/assets/index-65aMFXUF.css +2 -0
- package/client/dist/assets/index-MyctEsPU.js +116 -0
- package/client/dist/assets/javascript-CpIGwZ_Y.js +1 -0
- package/client/dist/assets/json-C3WlssX3.js +1 -0
- package/client/dist/assets/purify.es-Dqk5qvad.js +3 -0
- package/client/dist/assets/shikiBundle-DbyGgq42.js +12 -0
- package/client/dist/assets/{svelte-tEuLYt3E.js → svelte-CdeT-Ich.js} +1 -1
- package/client/dist/assets/tsx-CGosfAUg.js +1 -0
- package/client/dist/assets/typescript-Bb1J8qyy.js +1 -0
- package/client/dist/assets/{vue-Bg0byEaI.js → vue-jUI-lpPb.js} +1 -1
- package/client/dist/assets/wasm-inlined-4KdTHw0F.js +1 -0
- package/client/dist/index.html +3 -6
- package/package.json +37 -37
- package/server/dist/_virtual/_rolldown/runtime.cjs +1 -2
- package/server/dist/controllers/auth.controller.cjs +79 -0
- package/server/dist/controllers/auth.controller.cjs.map +1 -0
- package/server/dist/controllers/auth.controller.d.ts +34 -0
- package/server/dist/controllers/auth.controller.mjs +75 -0
- package/server/dist/controllers/auth.controller.mjs.map +1 -0
- package/server/dist/controllers/configuration.controller.cjs +10 -5
- package/server/dist/controllers/configuration.controller.cjs.map +1 -1
- package/server/dist/controllers/configuration.controller.d.ts +8 -3
- package/server/dist/controllers/configuration.controller.mjs +10 -5
- package/server/dist/controllers/configuration.controller.mjs.map +1 -1
- package/server/dist/controllers/dictionary.controller.cjs +4 -4
- package/server/dist/controllers/dictionary.controller.cjs.map +1 -1
- package/server/dist/controllers/dictionary.controller.d.ts +1 -2
- package/server/dist/controllers/dictionary.controller.mjs +3 -3
- package/server/dist/controllers/dictionary.controller.mjs.map +1 -1
- package/server/dist/export.cjs +2 -2
- package/server/dist/export.d.ts +2 -2
- package/server/dist/index.cjs +56 -19
- package/server/dist/index.cjs.map +1 -1
- package/server/dist/index.mjs +56 -19
- package/server/dist/index.mjs.map +1 -1
- package/server/dist/routes/auth.routes.cjs +34 -0
- package/server/dist/routes/auth.routes.cjs.map +1 -0
- package/server/dist/routes/auth.routes.d.ts +20 -0
- package/server/dist/routes/auth.routes.mjs +32 -0
- package/server/dist/routes/auth.routes.mjs.map +1 -0
- package/server/dist/routes/config.routes.cjs +2 -3
- package/server/dist/routes/config.routes.d.ts +0 -2
- package/server/dist/routes/config.routes.mjs +1 -2
- package/server/dist/routes/dictionary.routes.cjs +2 -3
- package/server/dist/routes/dictionary.routes.d.ts +0 -2
- package/server/dist/routes/dictionary.routes.mjs +1 -2
- package/server/dist/services/editorAuth.service.cjs +142 -0
- package/server/dist/services/editorAuth.service.cjs.map +1 -0
- package/server/dist/services/editorAuth.service.d.ts +41 -0
- package/server/dist/services/editorAuth.service.mjs +136 -0
- package/server/dist/services/editorAuth.service.mjs.map +1 -0
- package/server/dist/types/Routes.d.ts +0 -2
- package/server/dist/utils/checkPortAvailability.cjs +40 -15
- package/server/dist/utils/checkPortAvailability.cjs.map +1 -1
- package/server/dist/utils/checkPortAvailability.d.ts +14 -3
- package/server/dist/utils/checkPortAvailability.mjs +39 -15
- package/server/dist/utils/checkPortAvailability.mjs.map +1 -1
- package/server/dist/utils/httpStatusCodes.cjs +1 -2
- package/server/dist/utils/httpStatusCodes.d.ts +9 -20
- package/server/dist/utils/httpStatusCodes.mjs +1 -2
- package/server/dist/utils/responseData.cjs +2 -3
- package/server/dist/utils/responseData.d.ts +1 -2
- package/server/dist/utils/responseData.mjs +1 -2
- package/client/dist/assets/CodeBlockShiki-DtgHBhf-.js +0 -2
- package/client/dist/assets/MarkDownRender-B5rc5xdv.js +0 -25
- package/client/dist/assets/MarkDownRender-BJfBvDXr.js +0 -1
- package/client/dist/assets/MarkdownEditor-CKaCMWJN.js +0 -160
- package/client/dist/assets/codeTransformer-DVPQQcdP.js +0 -9
- package/client/dist/assets/css-CdtkT07m.js +0 -1
- package/client/dist/assets/css-LbU1hoFO.js +0 -1
- package/client/dist/assets/dist-BHukwvnD.js +0 -11
- package/client/dist/assets/dist-CcmWBeAo.js +0 -1
- package/client/dist/assets/dynamic-BG2syiTL.js +0 -41
- package/client/dist/assets/html-DYtkB_T1.js +0 -1
- package/client/dist/assets/index-BtBJMAbp.js +0 -59
- package/client/dist/assets/index-D82ZIHVs.css +0 -2
- package/client/dist/assets/javascript-Yelw-5ZN.js +0 -1
- package/client/dist/assets/json-CaljABEy.js +0 -1
- package/client/dist/assets/purify.es-Bvo9QlJ8.js +0 -3
- package/client/dist/assets/react-Cvdyeg_0.js +0 -1
- package/client/dist/assets/rolldown-runtime-hePW80VL.js +0 -1
- package/client/dist/assets/shikiBundle-vOk0aVqf.js +0 -12
- package/client/dist/assets/tsx-5f3ulCja.js +0 -1
- package/client/dist/assets/typescript-Utq2Cl8c.js +0 -1
- package/client/dist/assets/wasm-BnjxR4X6.js +0 -1
package/server/dist/index.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const require_runtime = require(
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_routes_auth_routes = require("./routes/auth.routes.cjs");
|
|
3
|
+
const require_routes_config_routes = require("./routes/config.routes.cjs");
|
|
4
|
+
const require_routes_dictionary_routes = require("./routes/dictionary.routes.cjs");
|
|
5
|
+
const require_utils_checkPortAvailability = require("./utils/checkPortAvailability.cjs");
|
|
5
6
|
let node_fs = require("node:fs");
|
|
6
7
|
let node_path = require("node:path");
|
|
7
8
|
let node_url = require("node:url");
|
|
@@ -22,13 +23,14 @@ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors, 1);
|
|
|
22
23
|
let _intlayer_config_env = require("@intlayer/config/env");
|
|
23
24
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
24
25
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
26
|
+
let _intlayer_engine_build = require("@intlayer/engine/build");
|
|
25
27
|
let fastify_intlayer = require("fastify-intlayer");
|
|
26
28
|
let fastify = require("fastify");
|
|
27
29
|
fastify = require_runtime.__toESM(fastify, 1);
|
|
28
30
|
let mime = require("mime");
|
|
29
31
|
mime = require_runtime.__toESM(mime, 1);
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
// src/index.ts
|
|
32
34
|
const __dirname$1 = (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
33
35
|
const envFileOptions = {
|
|
34
36
|
env: process.env.NODE_ENV,
|
|
@@ -37,13 +39,11 @@ const envFileOptions = {
|
|
|
37
39
|
const FALLBACK_PORT = 8e3;
|
|
38
40
|
const config = (0, _intlayer_config_node.getConfiguration)(envFileOptions);
|
|
39
41
|
const appLogger = (0, _intlayer_config_logger.getAppLogger)(config);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
process.exit(0);
|
|
44
|
-
}
|
|
42
|
+
/** Port tried first; the next free one is used when it is taken. */
|
|
43
|
+
const preferredPort = config.editor.port ?? FALLBACK_PORT;
|
|
44
|
+
const HOST = "0.0.0.0";
|
|
45
45
|
const packageJson = JSON.parse((0, node_fs.readFileSync)((0, node_path.resolve)(__dirname$1, "../../package.json"), "utf8"));
|
|
46
|
-
const app = (0, fastify.default)({ disableRequestLogging: true });
|
|
46
|
+
const app = (0, fastify.default)({ logController: new fastify.LogController({ disableRequestLogging: true }) });
|
|
47
47
|
app.register(fastify_intlayer.intlayer);
|
|
48
48
|
const clientDistPath = (0, node_path.resolve)(__dirname$1, "../../client/dist");
|
|
49
49
|
const corsOptions = {
|
|
@@ -51,12 +51,49 @@ const corsOptions = {
|
|
|
51
51
|
credentials: true
|
|
52
52
|
};
|
|
53
53
|
const startServer = async (app) => {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const port = await require_utils_checkPortAvailability.findAvailablePort(preferredPort, HOST);
|
|
55
|
+
if (port === void 0) {
|
|
56
|
+
appLogger(`Error: Port ${preferredPort} and the next ones are in use.`, { level: "error" });
|
|
56
57
|
process.exit(255);
|
|
57
58
|
}
|
|
59
|
+
if (port !== preferredPort) appLogger(`Port ${preferredPort} is in use, using port ${port} instead.`, { level: "warn" });
|
|
60
|
+
process.env[_intlayer_config_node.EDITOR_SERVER_PORT_ENV_VAR] = String(port);
|
|
61
|
+
const editorOverride = {
|
|
62
|
+
enabled: true,
|
|
63
|
+
editorURL: (0, _intlayer_config_node.getEditorURLForPort)(config.editor.editorURL, port)
|
|
64
|
+
};
|
|
65
|
+
const overriddenKeys = await (0, _intlayer_engine_build.overrideBuiltEditorConfiguration)(config, editorOverride);
|
|
66
|
+
if (overriddenKeys.length > 0) {
|
|
67
|
+
const overriddenSettings = overriddenKeys.map((key) => (0, _intlayer_config_logger.colorize)(`editor.${key}`, _intlayer_config_colors.BLUE));
|
|
68
|
+
appLogger(`${overriddenSettings.join(" and ")} temporarily adapted in ${(0, _intlayer_config_logger.colorizePath)((0, node_path.relative)(config.system.baseDir, config.system.configDir))}. Set it in ${(0, _intlayer_config_logger.colorizePath)("intlayer.config.ts")} to keep it after the next build.`, { level: "warn" });
|
|
69
|
+
(0, _intlayer_engine_build.watchBuiltEditorConfiguration)(config.system.configDir, {
|
|
70
|
+
loadConfiguration: () => (0, _intlayer_config_node.getConfiguration)({
|
|
71
|
+
...envFileOptions,
|
|
72
|
+
cache: false
|
|
73
|
+
}),
|
|
74
|
+
editorOverride,
|
|
75
|
+
onRestore: () => appLogger(`${overriddenSettings.join(" and ")} adapted again in ${(0, _intlayer_config_logger.colorizePath)((0, node_path.relative)(config.system.baseDir, config.system.configDir))} after the application rebuilt it.`),
|
|
76
|
+
onError: (error) => appLogger(`Failed to keep the editor settings in the built configuration: ${error.message}`, { level: "warn" })
|
|
77
|
+
});
|
|
78
|
+
}
|
|
58
79
|
await app.register(_fastify_helmet.default, {
|
|
59
|
-
contentSecurityPolicy:
|
|
80
|
+
contentSecurityPolicy: {
|
|
81
|
+
useDefaults: false,
|
|
82
|
+
directives: {
|
|
83
|
+
defaultSrc: _fastify_helmet.default.contentSecurityPolicy.dangerouslyDisableDefaultSrc,
|
|
84
|
+
frameAncestors: [
|
|
85
|
+
"'self'",
|
|
86
|
+
"vscode-webview:",
|
|
87
|
+
"vscode-file:",
|
|
88
|
+
"https://*.vscode-cdn.net",
|
|
89
|
+
"https://*.vscode-webview.net",
|
|
90
|
+
"localhost:*",
|
|
91
|
+
"http://localhost:*",
|
|
92
|
+
"http://127.0.0.1:*"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
frameguard: false,
|
|
60
97
|
global: true
|
|
61
98
|
});
|
|
62
99
|
await app.register(_fastify_cors.default, corsOptions);
|
|
@@ -65,6 +102,7 @@ const startServer = async (app) => {
|
|
|
65
102
|
await app.register(_fastify_formbody.default);
|
|
66
103
|
await app.register(require_routes_dictionary_routes.dictionaryRouter, { prefix: "/api/dictionary" });
|
|
67
104
|
await app.register(require_routes_config_routes.configurationRouter, { prefix: "/api/config" });
|
|
105
|
+
await app.register(require_routes_auth_routes.authRouter, { prefix: "/api/auth" });
|
|
68
106
|
await app.register(_fastify_static.default, {
|
|
69
107
|
root: clientDistPath,
|
|
70
108
|
wildcard: false
|
|
@@ -80,7 +118,7 @@ const startServer = async (app) => {
|
|
|
80
118
|
try {
|
|
81
119
|
await app.listen({
|
|
82
120
|
port,
|
|
83
|
-
host:
|
|
121
|
+
host: HOST
|
|
84
122
|
});
|
|
85
123
|
const dotEnvFilePath = (0, _intlayer_config_env.getEnvFilePath)(envFileOptions.env, envFileOptions.envFile);
|
|
86
124
|
console.log(`
|
|
@@ -91,12 +129,11 @@ const startServer = async (app) => {
|
|
|
91
129
|
${(0, _intlayer_config_logger.colorize)("➜", _intlayer_config_colors.GREY_DARK)} Access key: ${config.editor.clientId ?? "-"}
|
|
92
130
|
${(0, _intlayer_config_logger.colorize)("➜", _intlayer_config_colors.GREY_DARK)} Environment: ${dotEnvFilePath ?? "-"}
|
|
93
131
|
`);
|
|
94
|
-
} catch (
|
|
95
|
-
|
|
96
|
-
process.exit(1);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
appLogger(`Failed to start the editor: ${error.message}`, { level: "error" });
|
|
134
|
+
process.exit(error.code === "EADDRINUSE" ? 255 : 1);
|
|
97
135
|
}
|
|
98
136
|
};
|
|
99
137
|
startServer(app);
|
|
100
138
|
|
|
101
|
-
//#endregion
|
|
102
139
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["__dirname","dirname","fileURLToPath","getConfiguration","getAppLogger","colorize","ANSIColors","colorizePath","readFileSync","resolve","Fastify","intlayer","checkPortAvailability","fastifyHelmet","fastifyCors","fastifyCompress","fastifyCookie","fastifyFormbody","dictionaryRouter","configurationRouter","fastifyStatic","join","existsSync","lstatSync","getEnvFilePath"],"sources":["../src/index.ts"],"sourcesContent":["import { existsSync, lstatSync, readFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport fastifyCompress from '@fastify/compress';\nimport fastifyCookie from '@fastify/cookie';\nimport fastifyCors, { type FastifyCorsOptions } from '@fastify/cors';\nimport fastifyFormbody from '@fastify/formbody';\nimport fastifyHelmet from '@fastify/helmet';\nimport fastifyStatic from '@fastify/static';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { getEnvFilePath } from '@intlayer/config/env';\nimport { colorize, colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { configurationRouter } from '@routes/config.routes';\nimport { dictionaryRouter } from '@routes/dictionary.routes';\nimport { checkPortAvailability } from '@utils/checkPortAvailability';\nimport Fastify, { type FastifyInstance } from 'fastify';\nimport { intlayer } from 'fastify-intlayer';\nimport mime from 'mime';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst envFileOptions = {\n env: process.env.NODE_ENV,\n envFile: process.env.ENV_FILE,\n};\n\nconst FALLBACK_PORT = 8000;\nconst config = getConfiguration(envFileOptions);\n\nconst appLogger = getAppLogger(config);\nconst port = config.editor.port ?? FALLBACK_PORT;\n\nif (!config.editor.enabled) {\n appLogger(\n `Editor is not enabled. Add ${colorize('editor.enabled', ANSIColors.BLUE)} to ${colorizePath('intlayer.config.ts')} file to enable it.`,\n {\n level: 'error',\n }\n );\n process.exit(0);\n}\n\n// Load package.json\nconst packageJson = JSON.parse(\n readFileSync(resolve(__dirname, '../../package.json'), 'utf8')\n);\n\nconst app: FastifyInstance = Fastify({\n disableRequestLogging: true, // Optional: Keep logs clean like the original\n});\n\n// Load internationalization plugin\n// Assuming fastify-intlayer is the Fastify equivalent of express-intlayer\napp.register(intlayer);\n\nconst clientDistPath = resolve(__dirname, '../../client/dist');\n\nconst corsOptions: FastifyCorsOptions = {\n origin: '*',\n credentials: true,\n};\n\nconst startServer = async (app: FastifyInstance) => {\n const isPortAvailable = await checkPortAvailability(port);\n\n if (!isPortAvailable) {\n appLogger(`Error: Port ${port} is already in use.`, {\n level: 'error',\n });\n process.exit(255);\n }\n\n // Security Headers\n await app.register(fastifyHelmet, {\n contentSecurityPolicy: false,\n global: true,\n });\n\n // CORS\n await app.register(fastifyCors, corsOptions);\n\n // Compression\n await app.register(fastifyCompress);\n\n // Cookie Parser\n await app.register(fastifyCookie);\n\n // Parse application/x-www-form-urlencoded\n await app.register(fastifyFormbody);\n\n // Register Routes\n await app.register(dictionaryRouter, { prefix: '/api/dictionary' });\n await app.register(configurationRouter, { prefix: '/api/config' });\n\n // Serve Static Files\n await app.register(fastifyStatic, {\n root: clientDistPath,\n wildcard: false, // We handle the fallback manually to match SPA logic\n });\n\n // For single-page applications, redirect all unmatched routes to index.html\n app.setNotFoundHandler((req, reply) => {\n const requestedPath = join(clientDistPath, req.raw.url || '/');\n\n if (existsSync(requestedPath) && lstatSync(requestedPath).isFile()) {\n const mimeType =\n mime.getType(requestedPath) ?? 'application/octet-stream';\n reply.header('Content-Type', mimeType);\n return reply.sendFile(req.raw.url?.split('/').pop() || 'index.html');\n } else {\n return reply.sendFile('index.html');\n }\n });\n\n try {\n await app.listen({ port, host: '0.0.0.0' });\n\n const dotEnvFilePath = getEnvFilePath(\n envFileOptions.env,\n envFileOptions.envFile\n );\n\n console.log(`\n ${colorize(colorize('INTLAYER', ANSIColors.BOLD), ANSIColors.GREY_DARK)} ${colorize(`v${packageJson.version}`, ANSIColors.GREY_DARK)}\n\n Editor running at: ${colorizePath(`http://localhost:${port}`)}\n ${colorize('➜', ANSIColors.GREY_DARK)} Watching application at: ${config.editor.applicationURL === '' ? '-' : colorizePath(config.editor.applicationURL)}\n ${colorize('➜', ANSIColors.GREY_DARK)} Access key: ${config.editor.clientId ?? '-'}\n ${colorize('➜', ANSIColors.GREY_DARK)} Environment: ${dotEnvFilePath ?? '-'}\n `);\n } catch (err) {\n app.log.error(err);\n process.exit(1);\n }\n};\n\n// Start it up!\nstartServer(app);\n"],"mappings":";;;;;;;;;;;;;;;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,CAAC;CAGD,IAAI,oBAAoB,KAAK,UAAU;EACrC,MAAM,oBAAgBC,gBAAK,gBAAgB,IAAI,IAAI,OAAO,GAAG;EAE7D,QAAIC,oBAAW,aAAa,SAAKC,mBAAU,aAAa,CAAC,CAAC,OAAO,GAAG;GAClE,MAAM,WACJ,aAAK,QAAQ,aAAa,KAAK;GACjC,MAAM,OAAO,gBAAgB,QAAQ;GACrC,OAAO,MAAM,SAAS,IAAI,IAAI,KAAK,MAAM,GAAG,CAAC,CAAC,IAAI,KAAK,YAAY;EACrE,OACE,OAAO,MAAM,SAAS,YAAY;CAEtC,CAAC;CAED,IAAI;EACF,MAAM,IAAI,OAAO;GAAE;GAAM,MAAM;EAAU,CAAC;EAE1C,MAAM,qBAAiBC,qCACrB,eAAe,KACf,eAAe,OACjB;EAEA,QAAQ,IAAI;UACVnB,sCAASA,kCAAS,YAAYC,wBAAW,IAAI,GAAGA,wBAAW,SAAS,EAAE,OAAGD,kCAAS,IAAI,YAAY,WAAWC,wBAAW,SAAS,EAAE;;uCAEtGC,sCAAa,oBAAoB,MAAM,EAAE;UACtEF,kCAAS,KAAKC,wBAAW,SAAS,EAAE,8BAA8B,OAAO,OAAO,mBAAmB,KAAK,UAAMC,sCAAa,OAAO,OAAO,cAAc,EAAE;UACzJF,kCAAS,KAAKC,wBAAW,SAAS,EAAE,8BAA8B,OAAO,OAAO,YAAY,IAAI;UAChGD,kCAAS,KAAKC,wBAAW,SAAS,EAAE,8BAA8B,kBAAkB,IAAI;KACzF;CACH,SAAS,KAAK;EACZ,IAAI,IAAI,MAAM,GAAG;EACjB,QAAQ,KAAK,CAAC;CAChB;AACF;AAGA,YAAY,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["__dirname","dirname","fileURLToPath","getConfiguration","getAppLogger","readFileSync","resolve","Fastify","LogController","intlayer","findAvailablePort","EDITOR_SERVER_PORT_ENV_VAR","getEditorURLForPort","overrideBuiltEditorConfiguration","colorize","ANSIColors","colorizePath","relative","fastifyHelmet","fastifyCors","fastifyCompress","fastifyCookie","fastifyFormbody","dictionaryRouter","configurationRouter","authRouter","fastifyStatic","join","existsSync","lstatSync","getEnvFilePath"],"sources":["../src/index.ts"],"sourcesContent":["import { existsSync, lstatSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport fastifyCompress from '@fastify/compress';\nimport fastifyCookie from '@fastify/cookie';\nimport fastifyCors, { type FastifyCorsOptions } from '@fastify/cors';\nimport fastifyFormbody from '@fastify/formbody';\nimport fastifyHelmet from '@fastify/helmet';\nimport fastifyStatic from '@fastify/static';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { getEnvFilePath } from '@intlayer/config/env';\nimport { colorize, colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport {\n EDITOR_SERVER_PORT_ENV_VAR,\n getConfiguration,\n getEditorURLForPort,\n} from '@intlayer/config/node';\nimport {\n type BuiltEditorOverride,\n overrideBuiltEditorConfiguration,\n watchBuiltEditorConfiguration,\n} from '@intlayer/engine/build';\nimport { authRouter } from '@routes/auth.routes';\nimport { configurationRouter } from '@routes/config.routes';\nimport { dictionaryRouter } from '@routes/dictionary.routes';\nimport { findAvailablePort } from '@utils/checkPortAvailability';\nimport Fastify, { type FastifyInstance, LogController } from 'fastify';\nimport { intlayer } from 'fastify-intlayer';\nimport mime from 'mime';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst envFileOptions = {\n env: process.env.NODE_ENV,\n envFile: process.env.ENV_FILE,\n};\n\nconst FALLBACK_PORT = 8000;\nconst config = getConfiguration(envFileOptions);\n\nconst appLogger = getAppLogger(config);\n/** Port tried first; the next free one is used when it is taken. */\nconst preferredPort = config.editor.port ?? FALLBACK_PORT;\nconst HOST = '0.0.0.0';\n\n// Load package.json\nconst packageJson = JSON.parse(\n readFileSync(resolve(__dirname, '../../package.json'), 'utf8')\n);\n\nconst app: FastifyInstance = Fastify({\n logController: new LogController({\n disableRequestLogging: true, // Keep logs clean like the original\n }),\n});\n\n// Load internationalization plugin\n// Assuming fastify-intlayer is the Fastify equivalent of express-intlayer\napp.register(intlayer);\n\nconst clientDistPath = resolve(__dirname, '../../client/dist');\n\nconst corsOptions: FastifyCorsOptions = {\n origin: '*',\n credentials: true,\n};\n\nconst startServer = async (app: FastifyInstance) => {\n const port = await findAvailablePort(preferredPort, HOST);\n\n if (port === undefined) {\n appLogger(`Error: Port ${preferredPort} and the next ones are in use.`, {\n level: 'error',\n });\n process.exit(255);\n }\n\n if (port !== preferredPort) {\n appLogger(`Port ${preferredPort} is in use, using port ${port} instead.`, {\n level: 'warn',\n });\n }\n\n // Served by `/api/config`: the client calls the editor at its actual URL\n process.env[EDITOR_SERVER_PORT_ENV_VAR] = String(port);\n\n // Adapted in the built configuration only: the application must load the\n // editor client, and accept messages from the URL the editor is served at\n const editorOverride: BuiltEditorOverride = {\n enabled: true,\n editorURL: getEditorURLForPort(config.editor.editorURL, port),\n };\n const overriddenKeys = await overrideBuiltEditorConfiguration(\n config,\n editorOverride\n );\n\n if (overriddenKeys.length > 0) {\n const overriddenSettings = overriddenKeys.map((key) =>\n colorize(`editor.${key}`, ANSIColors.BLUE)\n );\n\n appLogger(\n `${overriddenSettings.join(' and ')} temporarily adapted in ${colorizePath(relative(config.system.baseDir, config.system.configDir))}. Set it in ${colorizePath('intlayer.config.ts')} to keep it after the next build.`,\n {\n level: 'warn',\n }\n );\n\n // An application (re)started aside rebuilds the configuration without them\n watchBuiltEditorConfiguration(config.system.configDir, {\n loadConfiguration: () =>\n getConfiguration({ ...envFileOptions, cache: false }),\n editorOverride,\n onRestore: () =>\n appLogger(\n `${overriddenSettings.join(' and ')} adapted again in ${colorizePath(relative(config.system.baseDir, config.system.configDir))} after the application rebuilt it.`\n ),\n onError: (error) =>\n appLogger(\n `Failed to keep the editor settings in the built configuration: ${(error as Error).message}`,\n { level: 'warn' }\n ),\n });\n }\n\n // Security Headers\n await app.register(fastifyHelmet, {\n // Only restrict who may frame the editor: itself and IDE webviews (the\n // VS Code extension panel). `X-Frame-Options` cannot list a scheme.\n contentSecurityPolicy: {\n useDefaults: false,\n directives: {\n // Helmet requires a `default-src`; the editor sets no other policy\n defaultSrc:\n fastifyHelmet.contentSecurityPolicy.dangerouslyDisableDefaultSrc,\n frameAncestors: [\n \"'self'\",\n 'vscode-webview:',\n 'vscode-file:',\n 'https://*.vscode-cdn.net',\n 'https://*.vscode-webview.net',\n 'localhost:*',\n 'http://localhost:*',\n 'http://127.0.0.1:*',\n ],\n },\n },\n frameguard: false,\n global: true,\n });\n\n // CORS\n await app.register(fastifyCors, corsOptions);\n\n // Compression\n await app.register(fastifyCompress);\n\n // Cookie Parser\n await app.register(fastifyCookie);\n\n // Parse application/x-www-form-urlencoded\n await app.register(fastifyFormbody);\n\n // Register Routes\n await app.register(dictionaryRouter, { prefix: '/api/dictionary' });\n await app.register(configurationRouter, { prefix: '/api/config' });\n await app.register(authRouter, { prefix: '/api/auth' });\n\n // Serve Static Files\n await app.register(fastifyStatic, {\n root: clientDistPath,\n wildcard: false, // We handle the fallback manually to match SPA logic\n });\n\n // For single-page applications, redirect all unmatched routes to index.html\n app.setNotFoundHandler((req, reply) => {\n const requestedPath = join(clientDistPath, req.raw.url || '/');\n\n if (existsSync(requestedPath) && lstatSync(requestedPath).isFile()) {\n const mimeType =\n mime.getType(requestedPath) ?? 'application/octet-stream';\n reply.header('Content-Type', mimeType);\n return reply.sendFile(req.raw.url?.split('/').pop() || 'index.html');\n } else {\n return reply.sendFile('index.html');\n }\n });\n\n try {\n await app.listen({ port, host: HOST });\n\n const dotEnvFilePath = getEnvFilePath(\n envFileOptions.env,\n envFileOptions.envFile\n );\n\n console.log(`\n ${colorize(colorize('INTLAYER', ANSIColors.BOLD), ANSIColors.GREY_DARK)} ${colorize(`v${packageJson.version}`, ANSIColors.GREY_DARK)}\n\n Editor running at: ${colorizePath(`http://localhost:${port}`)}\n ${colorize('➜', ANSIColors.GREY_DARK)} Watching application at: ${config.editor.applicationURL === '' ? '-' : colorizePath(config.editor.applicationURL)}\n ${colorize('➜', ANSIColors.GREY_DARK)} Access key: ${config.editor.clientId ?? '-'}\n ${colorize('➜', ANSIColors.GREY_DARK)} Environment: ${dotEnvFilePath ?? '-'}\n `);\n } catch (error) {\n // The Fastify logger is disabled, so `app.log` would swallow this\n appLogger(`Failed to start the editor: ${(error as Error).message}`, {\n level: 'error',\n });\n process.exit(\n (error as NodeJS.ErrnoException).code === 'EADDRINUSE' ? 255 : 1\n );\n }\n};\n\n// Start it up!\nstartServer(app);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAMA,kBAAYC,uBAAQC,qEAA6B,CAAC;AAExD,MAAM,iBAAiB;CACrB;CACA,SAAS,QAAQ,IAAI;AACvB;AAEA,MAAM,gBAAgB;AACtB,MAAM,aAASC,wCAAiB,cAAc;AAE9C,MAAM,gBAAYC,sCAAa,MAAM;;AAErC,MAAM,gBAAgB,OAAO,OAAO,QAAQ;AAC5C,MAAM,OAAO;AAGb,MAAM,cAAc,KAAK,UACvBC,0BAAaC,mBAAQN,aAAW,oBAAoB,GAAG,MAAM,CAC/D;AAEA,MAAM,UAAuBO,iBAAQ,EACnC,eAAe,IAAIC,sBAAc,EAC/B,uBAAuB,KACzB,CAAC,EACH,CAAC;AAID,IAAI,SAASC,yBAAQ;AAErB,MAAM,qBAAiBH,mBAAQN,aAAW,mBAAmB;AAE7D,MAAM,cAAkC;CACtC,QAAQ;CACR,aAAa;AACf;AAEA,MAAM,cAAc,OAAO,QAAyB;CAClD,MAAM,OAAO,MAAMU,sDAAkB,eAAe,IAAI;CAExD,IAAI,SAAS,QAAW;EACtB,UAAU,eAAe,cAAc,iCAAiC,EACtE,OAAO,QACT,CAAC;EACD,QAAQ,KAAK,GAAG;CAClB;CAEA,IAAI,SAAS,eACX,UAAU,QAAQ,cAAc,yBAAyB,KAAK,YAAY,EACxE,OAAO,OACT,CAAC;CAIH,QAAQ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|
|
1
|
+
import { authRouter } from "./routes/auth.routes.mjs";
|
|
1
2
|
import { configurationRouter } from "./routes/config.routes.mjs";
|
|
2
3
|
import { dictionaryRouter } from "./routes/dictionary.routes.mjs";
|
|
3
|
-
import {
|
|
4
|
+
import { findAvailablePort } from "./utils/checkPortAvailability.mjs";
|
|
4
5
|
import { existsSync, lstatSync, readFileSync } from "node:fs";
|
|
5
|
-
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
import fastifyCompress from "@fastify/compress";
|
|
8
9
|
import fastifyCookie from "@fastify/cookie";
|
|
@@ -13,12 +14,13 @@ import fastifyStatic from "@fastify/static";
|
|
|
13
14
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
14
15
|
import { getEnvFilePath } from "@intlayer/config/env";
|
|
15
16
|
import { colorize, colorizePath, getAppLogger } from "@intlayer/config/logger";
|
|
16
|
-
import { getConfiguration } from "@intlayer/config/node";
|
|
17
|
+
import { EDITOR_SERVER_PORT_ENV_VAR, getConfiguration, getEditorURLForPort } from "@intlayer/config/node";
|
|
18
|
+
import { overrideBuiltEditorConfiguration, watchBuiltEditorConfiguration } from "@intlayer/engine/build";
|
|
17
19
|
import { intlayer } from "fastify-intlayer";
|
|
18
|
-
import Fastify from "fastify";
|
|
20
|
+
import Fastify, { LogController } from "fastify";
|
|
19
21
|
import mime from "mime";
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
// src/index.ts
|
|
22
24
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
23
25
|
const envFileOptions = {
|
|
24
26
|
env: process.env.NODE_ENV,
|
|
@@ -27,13 +29,11 @@ const envFileOptions = {
|
|
|
27
29
|
const FALLBACK_PORT = 8e3;
|
|
28
30
|
const config = getConfiguration(envFileOptions);
|
|
29
31
|
const appLogger = getAppLogger(config);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
process.exit(0);
|
|
34
|
-
}
|
|
32
|
+
/** Port tried first; the next free one is used when it is taken. */
|
|
33
|
+
const preferredPort = config.editor.port ?? FALLBACK_PORT;
|
|
34
|
+
const HOST = "0.0.0.0";
|
|
35
35
|
const packageJson = JSON.parse(readFileSync(resolve(__dirname, "../../package.json"), "utf8"));
|
|
36
|
-
const app = Fastify({ disableRequestLogging: true });
|
|
36
|
+
const app = Fastify({ logController: new LogController({ disableRequestLogging: true }) });
|
|
37
37
|
app.register(intlayer);
|
|
38
38
|
const clientDistPath = resolve(__dirname, "../../client/dist");
|
|
39
39
|
const corsOptions = {
|
|
@@ -41,12 +41,49 @@ const corsOptions = {
|
|
|
41
41
|
credentials: true
|
|
42
42
|
};
|
|
43
43
|
const startServer = async (app) => {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const port = await findAvailablePort(preferredPort, HOST);
|
|
45
|
+
if (port === void 0) {
|
|
46
|
+
appLogger(`Error: Port ${preferredPort} and the next ones are in use.`, { level: "error" });
|
|
46
47
|
process.exit(255);
|
|
47
48
|
}
|
|
49
|
+
if (port !== preferredPort) appLogger(`Port ${preferredPort} is in use, using port ${port} instead.`, { level: "warn" });
|
|
50
|
+
process.env[EDITOR_SERVER_PORT_ENV_VAR] = String(port);
|
|
51
|
+
const editorOverride = {
|
|
52
|
+
enabled: true,
|
|
53
|
+
editorURL: getEditorURLForPort(config.editor.editorURL, port)
|
|
54
|
+
};
|
|
55
|
+
const overriddenKeys = await overrideBuiltEditorConfiguration(config, editorOverride);
|
|
56
|
+
if (overriddenKeys.length > 0) {
|
|
57
|
+
const overriddenSettings = overriddenKeys.map((key) => colorize(`editor.${key}`, ANSIColors.BLUE));
|
|
58
|
+
appLogger(`${overriddenSettings.join(" and ")} temporarily adapted in ${colorizePath(relative(config.system.baseDir, config.system.configDir))}. Set it in ${colorizePath("intlayer.config.ts")} to keep it after the next build.`, { level: "warn" });
|
|
59
|
+
watchBuiltEditorConfiguration(config.system.configDir, {
|
|
60
|
+
loadConfiguration: () => getConfiguration({
|
|
61
|
+
...envFileOptions,
|
|
62
|
+
cache: false
|
|
63
|
+
}),
|
|
64
|
+
editorOverride,
|
|
65
|
+
onRestore: () => appLogger(`${overriddenSettings.join(" and ")} adapted again in ${colorizePath(relative(config.system.baseDir, config.system.configDir))} after the application rebuilt it.`),
|
|
66
|
+
onError: (error) => appLogger(`Failed to keep the editor settings in the built configuration: ${error.message}`, { level: "warn" })
|
|
67
|
+
});
|
|
68
|
+
}
|
|
48
69
|
await app.register(fastifyHelmet, {
|
|
49
|
-
contentSecurityPolicy:
|
|
70
|
+
contentSecurityPolicy: {
|
|
71
|
+
useDefaults: false,
|
|
72
|
+
directives: {
|
|
73
|
+
defaultSrc: fastifyHelmet.contentSecurityPolicy.dangerouslyDisableDefaultSrc,
|
|
74
|
+
frameAncestors: [
|
|
75
|
+
"'self'",
|
|
76
|
+
"vscode-webview:",
|
|
77
|
+
"vscode-file:",
|
|
78
|
+
"https://*.vscode-cdn.net",
|
|
79
|
+
"https://*.vscode-webview.net",
|
|
80
|
+
"localhost:*",
|
|
81
|
+
"http://localhost:*",
|
|
82
|
+
"http://127.0.0.1:*"
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
frameguard: false,
|
|
50
87
|
global: true
|
|
51
88
|
});
|
|
52
89
|
await app.register(fastifyCors, corsOptions);
|
|
@@ -55,6 +92,7 @@ const startServer = async (app) => {
|
|
|
55
92
|
await app.register(fastifyFormbody);
|
|
56
93
|
await app.register(dictionaryRouter, { prefix: "/api/dictionary" });
|
|
57
94
|
await app.register(configurationRouter, { prefix: "/api/config" });
|
|
95
|
+
await app.register(authRouter, { prefix: "/api/auth" });
|
|
58
96
|
await app.register(fastifyStatic, {
|
|
59
97
|
root: clientDistPath,
|
|
60
98
|
wildcard: false
|
|
@@ -70,7 +108,7 @@ const startServer = async (app) => {
|
|
|
70
108
|
try {
|
|
71
109
|
await app.listen({
|
|
72
110
|
port,
|
|
73
|
-
host:
|
|
111
|
+
host: HOST
|
|
74
112
|
});
|
|
75
113
|
const dotEnvFilePath = getEnvFilePath(envFileOptions.env, envFileOptions.envFile);
|
|
76
114
|
console.log(`
|
|
@@ -81,12 +119,11 @@ const startServer = async (app) => {
|
|
|
81
119
|
${colorize("➜", ANSIColors.GREY_DARK)} Access key: ${config.editor.clientId ?? "-"}
|
|
82
120
|
${colorize("➜", ANSIColors.GREY_DARK)} Environment: ${dotEnvFilePath ?? "-"}
|
|
83
121
|
`);
|
|
84
|
-
} catch (
|
|
85
|
-
|
|
86
|
-
process.exit(1);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
appLogger(`Failed to start the editor: ${error.message}`, { level: "error" });
|
|
124
|
+
process.exit(error.code === "EADDRINUSE" ? 255 : 1);
|
|
87
125
|
}
|
|
88
126
|
};
|
|
89
127
|
startServer(app);
|
|
90
128
|
|
|
91
|
-
//#endregion
|
|
92
129
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { existsSync, lstatSync, readFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport fastifyCompress from '@fastify/compress';\nimport fastifyCookie from '@fastify/cookie';\nimport fastifyCors, { type FastifyCorsOptions } from '@fastify/cors';\nimport fastifyFormbody from '@fastify/formbody';\nimport fastifyHelmet from '@fastify/helmet';\nimport fastifyStatic from '@fastify/static';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { getEnvFilePath } from '@intlayer/config/env';\nimport { colorize, colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { configurationRouter } from '@routes/config.routes';\nimport { dictionaryRouter } from '@routes/dictionary.routes';\nimport { checkPortAvailability } from '@utils/checkPortAvailability';\nimport Fastify, { type FastifyInstance } from 'fastify';\nimport { intlayer } from 'fastify-intlayer';\nimport mime from 'mime';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst envFileOptions = {\n env: process.env.NODE_ENV,\n envFile: process.env.ENV_FILE,\n};\n\nconst FALLBACK_PORT = 8000;\nconst config = getConfiguration(envFileOptions);\n\nconst appLogger = getAppLogger(config);\nconst port = config.editor.port ?? FALLBACK_PORT;\n\nif (!config.editor.enabled) {\n appLogger(\n `Editor is not enabled. Add ${colorize('editor.enabled', ANSIColors.BLUE)} to ${colorizePath('intlayer.config.ts')} file to enable it.`,\n {\n level: 'error',\n }\n );\n process.exit(0);\n}\n\n// Load package.json\nconst packageJson = JSON.parse(\n readFileSync(resolve(__dirname, '../../package.json'), 'utf8')\n);\n\nconst app: FastifyInstance = Fastify({\n disableRequestLogging: true, // Optional: Keep logs clean like the original\n});\n\n// Load internationalization plugin\n// Assuming fastify-intlayer is the Fastify equivalent of express-intlayer\napp.register(intlayer);\n\nconst clientDistPath = resolve(__dirname, '../../client/dist');\n\nconst corsOptions: FastifyCorsOptions = {\n origin: '*',\n credentials: true,\n};\n\nconst startServer = async (app: FastifyInstance) => {\n const isPortAvailable = await checkPortAvailability(port);\n\n if (!isPortAvailable) {\n appLogger(`Error: Port ${port} is already in use.`, {\n level: 'error',\n });\n process.exit(255);\n }\n\n // Security Headers\n await app.register(fastifyHelmet, {\n contentSecurityPolicy: false,\n global: true,\n });\n\n // CORS\n await app.register(fastifyCors, corsOptions);\n\n // Compression\n await app.register(fastifyCompress);\n\n // Cookie Parser\n await app.register(fastifyCookie);\n\n // Parse application/x-www-form-urlencoded\n await app.register(fastifyFormbody);\n\n // Register Routes\n await app.register(dictionaryRouter, { prefix: '/api/dictionary' });\n await app.register(configurationRouter, { prefix: '/api/config' });\n\n // Serve Static Files\n await app.register(fastifyStatic, {\n root: clientDistPath,\n wildcard: false, // We handle the fallback manually to match SPA logic\n });\n\n // For single-page applications, redirect all unmatched routes to index.html\n app.setNotFoundHandler((req, reply) => {\n const requestedPath = join(clientDistPath, req.raw.url || '/');\n\n if (existsSync(requestedPath) && lstatSync(requestedPath).isFile()) {\n const mimeType =\n mime.getType(requestedPath) ?? 'application/octet-stream';\n reply.header('Content-Type', mimeType);\n return reply.sendFile(req.raw.url?.split('/').pop() || 'index.html');\n } else {\n return reply.sendFile('index.html');\n }\n });\n\n try {\n await app.listen({ port, host: '0.0.0.0' });\n\n const dotEnvFilePath = getEnvFilePath(\n envFileOptions.env,\n envFileOptions.envFile\n );\n\n console.log(`\n ${colorize(colorize('INTLAYER', ANSIColors.BOLD), ANSIColors.GREY_DARK)} ${colorize(`v${packageJson.version}`, ANSIColors.GREY_DARK)}\n\n Editor running at: ${colorizePath(`http://localhost:${port}`)}\n ${colorize('➜', ANSIColors.GREY_DARK)} Watching application at: ${config.editor.applicationURL === '' ? '-' : colorizePath(config.editor.applicationURL)}\n ${colorize('➜', ANSIColors.GREY_DARK)} Access key: ${config.editor.clientId ?? '-'}\n ${colorize('➜', ANSIColors.GREY_DARK)} Environment: ${dotEnvFilePath ?? '-'}\n `);\n } catch (err) {\n app.log.error(err);\n process.exit(1);\n }\n};\n\n// Start it up!\nstartServer(app);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAExD,MAAM,iBAAiB;CACrB;CACA,SAAS,QAAQ,IAAI;AACvB;AAEA,MAAM,gBAAgB;AACtB,MAAM,SAAS,iBAAiB,cAAc;AAE9C,MAAM,YAAY,aAAa,MAAM;AACrC,MAAM,OAAO,OAAO,OAAO,QAAQ;AAEnC,IAAI,CAAC,OAAO,OAAO,SAAS;CAC1B,UACE,8BAA8B,SAAS,kBAAkB,WAAW,IAAI,EAAE,MAAM,aAAa,oBAAoB,EAAE,sBACnH,EACE,OAAO,QACT,CACF;CACA,QAAQ,KAAK,CAAC;AAChB;AAGA,MAAM,cAAc,KAAK,MACvB,aAAa,QAAQ,WAAW,oBAAoB,GAAG,MAAM,CAC/D;AAEA,MAAM,MAAuB,QAAQ,EACn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W,SAAS,EAAE,GAAG,SAAS,IAAI,YAAY,WAAW,WAAW,SAAS,EAAE;;mCAEtG,aAAa,oBAAoB,MAAM,EAAE;MACtE,SAAS,KAAK,WAAW,SAAS,EAAE,8BAA8B,OAAO,OAAO,mBAAmB,KAAK,MAAM,aAAa,OAAO,OAAO,cAAc,EAAE;MACzJ,SAAS,KAAK,WAAW,SAAS,EAAE,8BAA8B,OAAO,OAAO,YAAY,IAAI;MAChG,SAAS,KAAK,WAAW,SAAS,EAAE,8BAA8B,kBAAkB,IAAI;KACzF;CACH,SAAS,KAAK;EACZ,IAAI,IAAI,MAAM,GAAG;EACjB,QAAQ,KAAK,CAAC;CAChB;AACF;AAGA,YAAY,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { existsSync, lstatSync, readFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport fastifyCompress from '@fastify/compress';\nimport fastifyCookie from '@fastify/cookie';\nimport fastifyCors, { type FastifyCorsOptions } from '@fastify/cors';\nimport fastifyFormbody from '@fastify/formbody';\nimport fastifyHelmet from '@fastify/helmet';\nimport fastifyStatic from '@fastify/static';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { getEnvFilePath } from '@intlayer/config/env';\nimport { colorize, colorizePath, getAppLogger } from '@intlayer/config/logger';\nimport {\n EDITOR_SERVER_PORT_ENV_VAR,\n getConfiguration,\n getEditorURLForPort,\n} from '@intlayer/config/node';\nimport {\n type BuiltEditorOverride,\n overrideBuiltEditorConfiguration,\n watchBuiltEditorConfiguration,\n} from '@intlayer/engine/build';\nimport { authRouter } from '@routes/auth.routes';\nimport { configurationRouter } from '@routes/config.routes';\nimport { dictionaryRouter } from '@routes/dictionary.routes';\nimport { findAvailablePort } from '@utils/checkPortAvailability';\nimport Fastify, { type FastifyInstance, LogController } from 'fastify';\nimport { intlayer } from 'fastify-intlayer';\nimport mime from 'mime';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst envFileOptions = {\n env: process.env.NODE_ENV,\n envFile: process.env.ENV_FILE,\n};\n\nconst FALLBACK_PORT = 8000;\nconst config = getConfiguration(envFileOptions);\n\nconst appLogger = getAppLogger(config);\n/** Port tried first; the next free one is used when it is taken. */\nconst preferredPort = config.editor.port ?? FALLBACK_PORT;\nconst HOST = '0.0.0.0';\n\n// Load package.json\nconst packageJson = JSON.parse(\n readFileSync(resolve(__dirname, '../../package.json'), 'utf8')\n);\n\nconst app: FastifyInstance = Fastify({\n logController: new LogController({\n disableRequestLogging: true, // Keep logs clean like the original\n }),\n});\n\n// Load internationalization plugin\n// Assuming fastify-intlayer is the Fastify equivalent of express-intlayer\napp.register(intlayer);\n\nconst clientDistPath = resolve(__dirname, '../../client/dist');\n\nconst corsOptions: FastifyCorsOptions = {\n origin: '*',\n credentials: true,\n};\n\nconst startServer = async (app: FastifyInstance) => {\n const port = await findAvailablePort(preferredPort, HOST);\n\n if (port === undefined) {\n appLogger(`Error: Port ${preferredPort} and the next ones are in use.`, {\n level: 'error',\n });\n process.exit(255);\n }\n\n if (port !== preferredPort) {\n appLogger(`Port ${preferredPort} is in use, using port ${port} instead.`, {\n level: 'warn',\n });\n }\n\n // Served by `/api/config`: the client calls the editor at its actual URL\n process.env[EDITOR_SERVER_PORT_ENV_VAR] = String(port);\n\n // Adapted in the built configuration only: the application must load the\n // editor client, and accept messages from the URL the editor is served at\n const editorOverride: BuiltEditorOverride = {\n enabled: true,\n editorURL: getEditorURLForPort(config.editor.editorURL, port),\n };\n const overriddenKeys = await overrideBuiltEditorConfiguration(\n config,\n editorOverride\n );\n\n if (overriddenKeys.length > 0) {\n const overriddenSettings = overriddenKeys.map((key) =>\n colorize(`editor.${key}`, ANSIColors.BLUE)\n );\n\n appLogger(\n `${overriddenSettings.join(' and ')} temporarily adapted in ${colorizePath(relative(config.system.baseDir, config.system.configDir))}. Set it in ${colorizePath('intlayer.config.ts')} to keep it after the next build.`,\n {\n level: 'warn',\n }\n );\n\n // An application (re)started aside rebuilds the configuration without them\n watchBuiltEditorConfiguration(config.system.configDir, {\n loadConfiguration: () =>\n getConfiguration({ ...envFileOptions, cache: false }),\n editorOverride,\n onRestore: () =>\n appLogger(\n `${overriddenSettings.join(' and ')} adapted again in ${colorizePath(relative(config.system.baseDir, config.system.configDir))} after the application rebuilt it.`\n ),\n onError: (error) =>\n appLogger(\n `Failed to keep the editor settings in the built configuration: ${(error as Error).message}`,\n { level: 'warn' }\n ),\n });\n }\n\n // Security Headers\n await app.register(fastifyHelmet, {\n // Only restrict who may frame the editor: itself and IDE webviews (the\n // VS Code extension panel). `X-Frame-Options` cannot list a scheme.\n contentSecurityPolicy: {\n useDefaults: false,\n directives: {\n // Helmet requires a `default-src`; the editor sets no other policy\n defaultSrc:\n fastifyHelmet.contentSecurityPolicy.dangerouslyDisableDefaultSrc,\n frameAncestors: [\n \"'self'\",\n 'vscode-webview:',\n 'vscode-file:',\n 'https://*.vscode-cdn.net',\n 'https://*.vscode-webview.net',\n 'localhost:*',\n 'http://localhost:*',\n 'http://127.0.0.1:*',\n ],\n },\n },\n frameguard: false,\n global: true,\n });\n\n // CORS\n await app.register(fastifyCors, corsOptions);\n\n // Compression\n await app.register(fastifyCompress);\n\n // Cookie Parser\n await app.register(fastifyCookie);\n\n // Parse application/x-www-form-urlencoded\n await app.register(fastifyFormbody);\n\n // Register Routes\n await app.register(dictionaryRouter, { prefix: '/api/dictionary' });\n await app.register(configurationRouter, { prefix: '/api/config' });\n await app.register(authRouter, { prefix: '/api/auth' });\n\n // Serve Static Files\n await app.register(fastifyStatic, {\n root: clientDistPath,\n wildcard: false, // We handle the fallback manually to match SPA logic\n });\n\n // For single-page applications, redirect all unmatched routes to index.html\n app.setNotFoundHandler((req, reply) => {\n const requestedPath = join(clientDistPath, req.raw.url || '/');\n\n if (existsSync(requestedPath) && lstatSync(requestedPath).isFile()) {\n const mimeType =\n mime.getType(requestedPath) ?? 'application/octet-stream';\n reply.header('Content-Type', mimeType);\n return reply.sendFile(req.raw.url?.split('/').pop() || 'index.html');\n } else {\n return reply.sendFile('index.html');\n }\n });\n\n try {\n await app.listen({ port, host: HOST });\n\n const dotEnvFilePath = getEnvFilePath(\n envFileOptions.env,\n envFileOptions.envFile\n );\n\n console.log(`\n ${colorize(colorize('INTLAYER', ANSIColors.BOLD), ANSIColors.GREY_DARK)} ${colorize(`v${packageJson.version}`, ANSIColors.GREY_DARK)}\n\n Editor running at: ${colorizePath(`http://localhost:${port}`)}\n ${colorize('➜', ANSIColors.GREY_DARK)} Watching application at: ${config.editor.applicationURL === '' ? '-' : colorizePath(config.editor.applicationURL)}\n ${colorize('➜', ANSIColors.GREY_DARK)} Access key: ${config.editor.clientId ?? '-'}\n ${colorize('➜', ANSIColors.GREY_DARK)} Environment: ${dotEnvFilePath ?? '-'}\n `);\n } catch (error) {\n // The Fastify logger is disabled, so `app.log` would swallow this\n appLogger(`Failed to start the editor: ${(error as Error).message}`, {\n level: 'error',\n });\n process.exit(\n (error as NodeJS.ErrnoException).code === 'EADDRINUSE' ? 255 : 1\n );\n }\n};\n\n// Start it up!\nstartServer(app);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAExD,MAAM,iBAAiB;CACrB;CACA,SAAS,QAAQ,IAAI;AACvB;AAEA,MAAM,gBAAgB;AACtB,MAAM,SAAS,iBAAiB,cAAc;AAE9C,MAAM,YAAY,aAAa,MAAM;;AAErC,MAAM,gBAAgB,OAAO,OAAO,QAAQ;AAC5C,MAAM,OAAO;AAGb,MAAM,cAAc,KAAK,MACvB,aAAa,QAAQ,WAAW,oBAAoB,GAAG,MAAM,CAC/D;AAEA,MAAM,MAAuB,QAAQ,EACnC,eAAe,IAAI,cAAc,EAC/B,uBAAuB,KACzB,CAAC,EACH,CAAC;AAID,IAAI,SAAS,QAAQ;AAErB,MAAM,iBAAiB,QAAQ,WAAW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AChG,SAAS,KAAK,WAAW,SAAS,EAAE,8BAA8B,kBAAkB,IAAI;KACzF;CACH,SAAS,OAAO;EAEd,UAAU,+BAAgC,MAAgB,WAAW,EACnE,OAAO,QACT,CAAC;EACD,QAAQ,KACL,MAAgC,SAAS,eAAe,MAAM,CACjE;CACF;AACF;AAGA,YAAY,GAAG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_controllers_auth_controller = require("../controllers/auth.controller.cjs");
|
|
3
|
+
let _intlayer_config_node = require("@intlayer/config/node");
|
|
4
|
+
|
|
5
|
+
// src/routes/auth.routes.ts
|
|
6
|
+
const { editor } = (0, _intlayer_config_node.getConfiguration)();
|
|
7
|
+
const getBaseURL = () => `${editor.editorURL}/api/auth`;
|
|
8
|
+
const getAuthRoutes = () => ({
|
|
9
|
+
getEditorAuth: {
|
|
10
|
+
urlModel: "/",
|
|
11
|
+
url: getBaseURL(),
|
|
12
|
+
method: "GET"
|
|
13
|
+
},
|
|
14
|
+
startLogin: {
|
|
15
|
+
urlModel: "/login",
|
|
16
|
+
url: `${getBaseURL()}/login`,
|
|
17
|
+
method: "POST"
|
|
18
|
+
},
|
|
19
|
+
logout: {
|
|
20
|
+
urlModel: "/logout",
|
|
21
|
+
url: `${getBaseURL()}/logout`,
|
|
22
|
+
method: "POST"
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const authRouter = async (fastify) => {
|
|
26
|
+
fastify.addHook("onRequest", require_controllers_auth_controller.assertSameOrigin);
|
|
27
|
+
fastify.get(getAuthRoutes().getEditorAuth.urlModel, require_controllers_auth_controller.getEditorAuth);
|
|
28
|
+
fastify.post(getAuthRoutes().startLogin.urlModel, require_controllers_auth_controller.startLogin);
|
|
29
|
+
fastify.post(getAuthRoutes().logout.urlModel, require_controllers_auth_controller.logout);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.authRouter = authRouter;
|
|
33
|
+
exports.getAuthRoutes = getAuthRoutes;
|
|
34
|
+
//# sourceMappingURL=auth.routes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.routes.cjs","names":["getConfiguration","assertSameOrigin","getEditorAuth","startLogin","logout"],"sources":["../../src/routes/auth.routes.ts"],"sourcesContent":["import {\n assertSameOrigin,\n getEditorAuth,\n logout,\n startLogin,\n} from '@controllers/auth.controller';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { FastifyInstance } from 'fastify';\nimport type { Routes } from '@/types/Routes';\n\nconst { editor } = getConfiguration();\n\nconst getBaseURL = () => `${editor.editorURL}/api/auth`;\n\nexport const getAuthRoutes = () =>\n ({\n getEditorAuth: {\n urlModel: '/',\n url: getBaseURL(),\n method: 'GET',\n },\n startLogin: {\n urlModel: '/login',\n url: `${getBaseURL()}/login`,\n method: 'POST',\n },\n logout: {\n urlModel: '/logout',\n url: `${getBaseURL()}/logout`,\n method: 'POST',\n },\n }) satisfies Routes;\n\nexport const authRouter = async (fastify: FastifyInstance) => {\n fastify.addHook('onRequest', assertSameOrigin);\n\n fastify.get(getAuthRoutes().getEditorAuth.urlModel, getEditorAuth);\n fastify.post(getAuthRoutes().startLogin.urlModel, startLogin);\n fastify.post(getAuthRoutes().logout.urlModel, logout);\n};\n"],"mappings":";;;;;AAUA,MAAM,EAAE,eAAWA,wCAAiB;AAEpC,MAAM,mBAAmB,GAAG,OAAO,UAAU;AAE7C,MAAa,uBACV;CACC,eAAe;EACb,UAAU;EACV,KAAK,WAAW;EAChB,QAAQ;CACV;CACA,YAAY;EACV,UAAU;EACV,KAAK,GAAG,WAAW,EAAE;EACrB,QAAQ;CACV;CACA,QAAQ;EACN,UAAU;EACV,KAAK,GAAG,WAAW,EAAE;EACrB,QAAQ;CACV;AACF;AAEF,MAAa,aAAa,OAAO,YAA6B;CAC5D,QAAQ,QAAQ,aAAaC,oDAAgB;CAE7C,QAAQ,IAAI,cAAc,CAAC,CAAC,cAAc,UAAUC,iDAAa;CACjE,QAAQ,KAAK,cAAc,CAAC,CAAC,WAAW,UAAUC,8CAAU;CAC5D,QAAQ,KAAK,cAAc,CAAC,CAAC,OAAO,UAAUC,0CAAM;AACtD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FastifyInstance } from "fastify";
|
|
2
|
+
export declare const getAuthRoutes: () => {
|
|
3
|
+
getEditorAuth: {
|
|
4
|
+
urlModel: string;
|
|
5
|
+
url: string;
|
|
6
|
+
method: "GET";
|
|
7
|
+
};
|
|
8
|
+
startLogin: {
|
|
9
|
+
urlModel: string;
|
|
10
|
+
url: string;
|
|
11
|
+
method: "POST";
|
|
12
|
+
};
|
|
13
|
+
logout: {
|
|
14
|
+
urlModel: string;
|
|
15
|
+
url: string;
|
|
16
|
+
method: "POST";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare const authRouter: (fastify: FastifyInstance) => Promise<void>;
|
|
20
|
+
//# sourceMappingURL=auth.routes.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { assertSameOrigin, getEditorAuth, logout, startLogin } from "../controllers/auth.controller.mjs";
|
|
2
|
+
import { getConfiguration } from "@intlayer/config/node";
|
|
3
|
+
|
|
4
|
+
// src/routes/auth.routes.ts
|
|
5
|
+
const { editor } = getConfiguration();
|
|
6
|
+
const getBaseURL = () => `${editor.editorURL}/api/auth`;
|
|
7
|
+
const getAuthRoutes = () => ({
|
|
8
|
+
getEditorAuth: {
|
|
9
|
+
urlModel: "/",
|
|
10
|
+
url: getBaseURL(),
|
|
11
|
+
method: "GET"
|
|
12
|
+
},
|
|
13
|
+
startLogin: {
|
|
14
|
+
urlModel: "/login",
|
|
15
|
+
url: `${getBaseURL()}/login`,
|
|
16
|
+
method: "POST"
|
|
17
|
+
},
|
|
18
|
+
logout: {
|
|
19
|
+
urlModel: "/logout",
|
|
20
|
+
url: `${getBaseURL()}/logout`,
|
|
21
|
+
method: "POST"
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const authRouter = async (fastify) => {
|
|
25
|
+
fastify.addHook("onRequest", assertSameOrigin);
|
|
26
|
+
fastify.get(getAuthRoutes().getEditorAuth.urlModel, getEditorAuth);
|
|
27
|
+
fastify.post(getAuthRoutes().startLogin.urlModel, startLogin);
|
|
28
|
+
fastify.post(getAuthRoutes().logout.urlModel, logout);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { authRouter, getAuthRoutes };
|
|
32
|
+
//# sourceMappingURL=auth.routes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.routes.mjs","names":[],"sources":["../../src/routes/auth.routes.ts"],"sourcesContent":["import {\n assertSameOrigin,\n getEditorAuth,\n logout,\n startLogin,\n} from '@controllers/auth.controller';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { FastifyInstance } from 'fastify';\nimport type { Routes } from '@/types/Routes';\n\nconst { editor } = getConfiguration();\n\nconst getBaseURL = () => `${editor.editorURL}/api/auth`;\n\nexport const getAuthRoutes = () =>\n ({\n getEditorAuth: {\n urlModel: '/',\n url: getBaseURL(),\n method: 'GET',\n },\n startLogin: {\n urlModel: '/login',\n url: `${getBaseURL()}/login`,\n method: 'POST',\n },\n logout: {\n urlModel: '/logout',\n url: `${getBaseURL()}/logout`,\n method: 'POST',\n },\n }) satisfies Routes;\n\nexport const authRouter = async (fastify: FastifyInstance) => {\n fastify.addHook('onRequest', assertSameOrigin);\n\n fastify.get(getAuthRoutes().getEditorAuth.urlModel, getEditorAuth);\n fastify.post(getAuthRoutes().startLogin.urlModel, startLogin);\n fastify.post(getAuthRoutes().logout.urlModel, logout);\n};\n"],"mappings":";;;;AAUA,MAAM,EAAE,WAAW,iBAAiB;AAEpC,MAAM,mBAAmB,GAAG,OAAO,UAAU;AAE7C,MAAa,uBACV;CACC,eAAe;EACb,UAAU;EACV,KAAK,WAAW;EAChB,QAAQ;CACV;CACA,YAAY;EACV,UAAU;EACV,KAAK,GAAG,WAAW,EAAE;EACrB,QAAQ;CACV;CACA,QAAQ;EACN,UAAU;EACV,KAAK,GAAG,WAAW,EAAE;EACrB,QAAQ;CACV;AACF;AAEF,MAAa,aAAa,OAAO,YAA6B;CAC5D,QAAQ,QAAQ,aAAa,gBAAgB;CAE7C,QAAQ,IAAI,cAAc,CAAC,CAAC,cAAc,UAAU,aAAa;CACjE,QAAQ,KAAK,cAAc,CAAC,CAAC,WAAW,UAAU,UAAU;CAC5D,QAAQ,KAAK,cAAc,CAAC,CAAC,OAAO,UAAU,MAAM;AACtD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_controllers_configuration_controller = require(
|
|
2
|
+
const require_controllers_configuration_controller = require("../controllers/configuration.controller.cjs");
|
|
3
3
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/routes/config.routes.ts
|
|
6
6
|
const { editor } = (0, _intlayer_config_node.getConfiguration)();
|
|
7
7
|
const getBaseURL = () => `${editor.editorURL}/api/dictionary`;
|
|
8
8
|
const getConfigurationRoutes = () => ({ getConfiguration: {
|
|
@@ -14,7 +14,6 @@ const configurationRouter = async (fastify) => {
|
|
|
14
14
|
fastify.get(getConfigurationRoutes().getConfiguration.urlModel, require_controllers_configuration_controller.getConfiguration);
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
//#endregion
|
|
18
17
|
exports.configurationRouter = configurationRouter;
|
|
19
18
|
exports.getConfigurationRoutes = getConfigurationRoutes;
|
|
20
19
|
//# sourceMappingURL=config.routes.cjs.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FastifyInstance } from "fastify";
|
|
2
|
-
//#region src/routes/config.routes.d.ts
|
|
3
2
|
export declare const getConfigurationRoutes: () => {
|
|
4
3
|
getConfiguration: {
|
|
5
4
|
urlModel: string;
|
|
@@ -8,5 +7,4 @@ export declare const getConfigurationRoutes: () => {
|
|
|
8
7
|
};
|
|
9
8
|
};
|
|
10
9
|
export declare const configurationRouter: (fastify: FastifyInstance) => Promise<void>;
|
|
11
|
-
//#endregion
|
|
12
10
|
//# sourceMappingURL=config.routes.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getConfiguration as getConfiguration$1 } from "../controllers/configuration.controller.mjs";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/node";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/routes/config.routes.ts
|
|
5
5
|
const { editor } = getConfiguration();
|
|
6
6
|
const getBaseURL = () => `${editor.editorURL}/api/dictionary`;
|
|
7
7
|
const getConfigurationRoutes = () => ({ getConfiguration: {
|
|
@@ -13,6 +13,5 @@ const configurationRouter = async (fastify) => {
|
|
|
13
13
|
fastify.get(getConfigurationRoutes().getConfiguration.urlModel, getConfiguration$1);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
//#endregion
|
|
17
16
|
export { configurationRouter, getConfigurationRoutes };
|
|
18
17
|
//# sourceMappingURL=config.routes.mjs.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_controllers_dictionary_controller = require(
|
|
2
|
+
const require_controllers_dictionary_controller = require("../controllers/dictionary.controller.cjs");
|
|
3
3
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/routes/dictionary.routes.ts
|
|
6
6
|
const { editor } = (0, _intlayer_config_node.getConfiguration)();
|
|
7
7
|
const getBaseURL = () => `${editor.editorURL}/api/dictionary`;
|
|
8
8
|
const getDictionaryRoutes = () => ({
|
|
@@ -22,7 +22,6 @@ const dictionaryRouter = async (fastify) => {
|
|
|
22
22
|
fastify.post(getDictionaryRoutes().writeContentDeclaration.urlModel, require_controllers_dictionary_controller.writeContentDeclaration);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
//#endregion
|
|
26
25
|
exports.dictionaryRouter = dictionaryRouter;
|
|
27
26
|
exports.getDictionaryRoutes = getDictionaryRoutes;
|
|
28
27
|
//# sourceMappingURL=dictionary.routes.cjs.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FastifyInstance } from "fastify";
|
|
2
|
-
//#region src/routes/dictionary.routes.d.ts
|
|
3
2
|
export declare const getDictionaryRoutes: () => {
|
|
4
3
|
getDictionaries: {
|
|
5
4
|
urlModel: string;
|
|
@@ -13,5 +12,4 @@ export declare const getDictionaryRoutes: () => {
|
|
|
13
12
|
};
|
|
14
13
|
};
|
|
15
14
|
export declare const dictionaryRouter: (fastify: FastifyInstance) => Promise<void>;
|
|
16
|
-
//#endregion
|
|
17
15
|
//# sourceMappingURL=dictionary.routes.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getDictionaries, writeContentDeclaration } from "../controllers/dictionary.controller.mjs";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config/node";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/routes/dictionary.routes.ts
|
|
5
5
|
const { editor } = getConfiguration();
|
|
6
6
|
const getBaseURL = () => `${editor.editorURL}/api/dictionary`;
|
|
7
7
|
const getDictionaryRoutes = () => ({
|
|
@@ -21,6 +21,5 @@ const dictionaryRouter = async (fastify) => {
|
|
|
21
21
|
fastify.post(getDictionaryRoutes().writeContentDeclaration.urlModel, writeContentDeclaration);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
//#endregion
|
|
25
24
|
export { dictionaryRouter, getDictionaryRoutes };
|
|
26
25
|
//# sourceMappingURL=dictionary.routes.mjs.map
|