-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.js
More file actions
169 lines (144 loc) · 6.37 KB
/
bootstrap.js
File metadata and controls
169 lines (144 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// #region F I L E
// <copyright file="mcode-package/bootstrap.js" company="MicroCODE Incorporated">Copyright © 2022-2024 MicroCODE, Inc. Troy, MI</copyright><author>Timothy J. McGuire</author>
// #region M O D U L E
// #region D O C U M E N T A T I O N
/**
* Project: MicroCODE MERN Applications
* Customer: Internal + MIT xPRO Course
* @module 'bootstrap.js'
* @memberof mcode
* @created January 2022-2024
* @author Timothy McGuire, MicroCODE, Inc.
* @description >
* Loads the absolute minimum set of modules needed to run a MicroCODE Web App.
*
* LICENSE:
* --------
* MIT License: MicroCODE.mcode-list
*
* Copyright (c) 2022-2024 Timothy McGuire, MicroCODE, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
* DESCRIPTION:
* ------------
* This module implements the core functionality required for the application to initialize and load necessary components.
* It sets up the environment, loads configuration files, and initializes the MicroCODE package.
*
* This module must be the very first thing imported (loaded) in any Web App's 'server.js'.
*
*
* TO USE:
* -------
* in our 'server.js', as the very first line of code, add...
*
* // MicroCODE Web App Bootstrap...
* require('./bootstrap.js');
*
* ...from that point forward you can use all the MicroCODE pakacges you have installed thru the global:
*
* mcode.* e.g.: mcode.Log(), mcode.warn(), mcode.success(), mcode.swap(), etc.
*
*
*
* REFERENCES:
* -----------
* 1. MIT xPRO Course: Professional Certificate in Coding: Full Stack Development with MERN
*
* 2. MicroCODE JavaScript Style Guide
* Local File: MCX-S02 (Internal JS Style Guide).docx
* https://github.com/MicroCODEIncorporated/JavaScriptSG
*
* 3. MicroCODE 'mcode-package' collection
* Local File: bootstrap.js
* https://www.npmjs.com/package/mcode-package
*
*
*
* MODIFICATIONS:
* --------------
* Date: By-Group: Rev: Description:
*
* 30-Jan-2024 TJM-MCODE {0001} New module to bootstrap all our public MicroCODE packages as a bare minimum App launch.
*
*
*
*
* NOTE: This module follow's MicroCODE's JavaScript Style Guide and Template JS file, see:
*
* o https://github.com/MicroCODEIncorporated/JavaScriptSG
* o https://github.com/MicroCODEIncorporated/TemplatesJS
*
* ...be sure to check out the CTRL-SHIFT+K, +L, +J keybaord shortcuts in Visual Studio Code
* for taking advance of the #regions in this file and our templates.
*
*
*/
// #endregion
// #region I M P O R T S
const path = require('path');
// #endregion
// #region G L O B A L S
console.log('');
console.log('[BOOTSTRAP] Loading minimum web app environment...');
// show NODE the location of our project's Config files
process.env["NODE_CONFIG_DIR"] = path.resolve(__dirname, './cfg/');
// Load the NODE environment dynamically based on NODE_ENV
global.dotenv = require('dotenv');
global.envMode = process.env.NODE_ENV; // The environment mode (based on NODE_ENV)
global.envFile = __dirname.includes('.dist') ? path.resolve(__dirname, '.env') : path.resolve(__dirname, `.env.${envMode}`);
global.dotenv.config({path: global.envFile});
// Load our JavaScript extensions
require('./utx/prototypes.js');
// Make the MicroCODE package available globally, from a single read-only object
global.mcode = require('mcode-package'); // MicroCODE's packages: mcode-data, mcode-log, mcode-list, ncode-cache, etc.
global.mcode.evtx = require('./ssr/ssr.js').evtx; // add extension to mcode.resx() a function to send HTMX BANNER responses to UI
global.dirBase = __dirname; // process.env.UI_SERVER_DIR; // The base directory of the Server (based on ENV MODE)
global.urlBase = process.env.UI_SERVER_URL; // The base URL for the Server
// App's Database Mode Settings
global.DB_MODE = 'backend:DB_MODE'; // Define a CACHE Key to control access to database, its either UI_SERVER_DB or UI_SERVER_DBAPI
global.DB_MODE_PG = process.env.UI_SERVER_DB || 'PostgreSQL'; // Local/Native Database
global.DB_MODE_API = process.env.UI_SERVER_DBAPI || 'MCODE'; // Remote Database API
// App's Global Namespace
global.UI_NAMESPACE = process.env.UI_SERVER_NAMESPACE || 'MCODE-APP'; // User Interface (UI)
// #endregion
// #region C O N S T A N T S
// Define this module's name for the 'mcode.log' package and documentation
const MODULE_NAME = 'bootstrap.js';
// #endregion
// #region M E T H O D S
// log what we're working with...
mcode.info({
source: MODULE_NAME,
envMode: global.envMode,
envFile: global.envFile,
dirBase: global.dirBase,
urlBase: global.urlBase,
//` env: process.env <-- uncomment for debugging .ENV issues
}, MODULE_NAME);
// add custom globals functions to 'mcode.' here...
// Define our 'root' based on environment...
mcode.root = typeof globalThis !== 'undefined'
? globalThis
: (typeof self !== 'undefined' ? self : (typeof window !== 'undefined' ? window : this));
mcode.success('Successfully loaded minimum web app environment.');
// #endregion
// #endregion
// #endregion