express-sweet-generator 2.0.10 → 2.0.12
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/LICENSE +1 -1
- package/bin/express-sweet-cli.js +222 -221
- package/package.json +1 -1
- package/templates/cjs/config/authentication.js +1 -2
- package/templates/cjs/config/config.js +1 -2
- package/templates/cjs/config/view.js +6 -3
- package/templates/cjs/ecosystem.config.js.ejs +1 -0
- package/templates/cjs/nginx.sample.conf.ejs +47 -47
- package/templates/cjs/views/layout/default.hbs +10 -1
- package/templates/client/webpack.config.js +3 -0
- package/templates/esm/config/authentication.js +1 -2
- package/templates/esm/config/config.js +1 -2
- package/templates/esm/config/view.js +6 -3
- package/templates/esm/{ecosystem.config.js.ejs → ecosystem.config.cjs.ejs} +1 -0
- package/templates/esm/nginx.sample.conf.ejs +47 -47
- package/templates/esm/package.json.ejs +6 -3
- package/templates/esm/views/layout/default.hbs +10 -1
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2025 Takuya Motoshima
|
|
2
2
|
|
|
3
3
|
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:
|
|
4
4
|
|
package/bin/express-sweet-cli.js
CHANGED
|
@@ -1,222 +1,223 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const ejs = require('ejs');
|
|
3
|
-
const fs = require('fs-extra');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const program = require('commander');
|
|
6
|
-
const readline = require('readline');
|
|
7
|
-
const util = require('util');
|
|
8
|
-
const version = require('../package').version;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Install an around function; AOP.
|
|
12
|
-
*/
|
|
13
|
-
function around(obj, method, fn) {
|
|
14
|
-
const old = obj[method];
|
|
15
|
-
obj[method] = function() {
|
|
16
|
-
return fn.call(this, old, [...arguments]);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Install a before function; AOP.
|
|
22
|
-
*/
|
|
23
|
-
function before(obj, method, fn) {
|
|
24
|
-
const old = obj[method];
|
|
25
|
-
obj[method] = function() {
|
|
26
|
-
fn.call(this);
|
|
27
|
-
old.apply(this, arguments);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Prompt for confirmation on STDOUT/STDIN
|
|
33
|
-
*/
|
|
34
|
-
function confirm(message, callback) {
|
|
35
|
-
const rl = readline.createInterface({input: process.stdin, output: process.stdout})
|
|
36
|
-
rl.question(message, input => {
|
|
37
|
-
rl.close();
|
|
38
|
-
callback(/^y|yes|ok|true$/i.test(input))
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Create application at the given directory.
|
|
44
|
-
*/
|
|
45
|
-
function createApplication(appName, installDir) {
|
|
46
|
-
// Output blank line.
|
|
47
|
-
console.log();
|
|
48
|
-
|
|
49
|
-
// Application listening port.
|
|
50
|
-
const port = program.port;
|
|
51
|
-
|
|
52
|
-
// Copy the entire template as a creation application.
|
|
53
|
-
const output = program.output === 'esm' ? 'esm' : 'cjs';
|
|
54
|
-
const templateDir = path.join(__dirname, '..', `templates/${output}`);
|
|
55
|
-
fs.copySync(templateDir, installDir);
|
|
56
|
-
|
|
57
|
-
// Copy bin/www.
|
|
58
|
-
compile(path.join(installDir, 'bin/www'), {name: appName});
|
|
59
|
-
|
|
60
|
-
// Copy ecosystem.config.js.
|
|
61
|
-
compile(path.join(installDir, 'ecosystem.config.js'), {name: appName, port});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
console.log(
|
|
78
|
-
console.log(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
console.log(
|
|
84
|
-
console.log(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
console.log(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.replace(
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @param {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
//
|
|
128
|
-
// https://github.com/
|
|
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
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
.
|
|
215
|
-
.
|
|
216
|
-
.
|
|
217
|
-
.option('-
|
|
218
|
-
.option('-
|
|
219
|
-
.
|
|
220
|
-
|
|
221
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const ejs = require('ejs');
|
|
3
|
+
const fs = require('fs-extra');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const program = require('commander');
|
|
6
|
+
const readline = require('readline');
|
|
7
|
+
const util = require('util');
|
|
8
|
+
const version = require('../package').version;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Install an around function; AOP.
|
|
12
|
+
*/
|
|
13
|
+
function around(obj, method, fn) {
|
|
14
|
+
const old = obj[method];
|
|
15
|
+
obj[method] = function() {
|
|
16
|
+
return fn.call(this, old, [...arguments]);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Install a before function; AOP.
|
|
22
|
+
*/
|
|
23
|
+
function before(obj, method, fn) {
|
|
24
|
+
const old = obj[method];
|
|
25
|
+
obj[method] = function() {
|
|
26
|
+
fn.call(this);
|
|
27
|
+
old.apply(this, arguments);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Prompt for confirmation on STDOUT/STDIN
|
|
33
|
+
*/
|
|
34
|
+
function confirm(message, callback) {
|
|
35
|
+
const rl = readline.createInterface({input: process.stdin, output: process.stdout})
|
|
36
|
+
rl.question(message, input => {
|
|
37
|
+
rl.close();
|
|
38
|
+
callback(/^y|yes|ok|true$/i.test(input))
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create application at the given directory.
|
|
44
|
+
*/
|
|
45
|
+
function createApplication(appName, installDir) {
|
|
46
|
+
// Output blank line.
|
|
47
|
+
console.log();
|
|
48
|
+
|
|
49
|
+
// Application listening port.
|
|
50
|
+
const port = program.port;
|
|
51
|
+
|
|
52
|
+
// Copy the entire template as a creation application.
|
|
53
|
+
const output = program.output === 'esm' ? 'esm' : 'cjs';
|
|
54
|
+
const templateDir = path.join(__dirname, '..', `templates/${output}`);
|
|
55
|
+
fs.copySync(templateDir, installDir);
|
|
56
|
+
|
|
57
|
+
// Copy bin/www.
|
|
58
|
+
compile(path.join(installDir, 'bin/www'), {name: appName});
|
|
59
|
+
|
|
60
|
+
// Copy ecosystem.config.js.
|
|
61
|
+
compile(path.join(installDir, program.output === 'esm' ? 'ecosystem.config.cjs' : 'ecosystem.config.js'), {name: appName, port});
|
|
62
|
+
// compile(path.join(installDir, 'ecosystem.config.js'), {name: appName, port});
|
|
63
|
+
|
|
64
|
+
// Copy nginx.sample.conf.
|
|
65
|
+
compile(path.join(installDir, 'nginx.sample.conf'), {name: appName, port});
|
|
66
|
+
|
|
67
|
+
// Copy package.json.
|
|
68
|
+
compile(path.join(installDir, 'package.json'), {name: appName});
|
|
69
|
+
|
|
70
|
+
// Copy the front-end module (template/client) to the installation directory.
|
|
71
|
+
const templateClientDir = path.join(__dirname, '../templates/client');
|
|
72
|
+
fs.copySync(templateClientDir, `${installDir.replace(/\/$/, '')}/client`);
|
|
73
|
+
|
|
74
|
+
const prompt = launchedFromCmd() ? '>' : '$'
|
|
75
|
+
if (installDir !== '.') {
|
|
76
|
+
// Output blank line.
|
|
77
|
+
console.log();
|
|
78
|
+
console.log(' change directory:');
|
|
79
|
+
console.log(` ${prompt} cd ${installDir}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Output blank line.
|
|
83
|
+
console.log();
|
|
84
|
+
console.log(' install dependencies:');
|
|
85
|
+
console.log(` ${prompt} npm install`);
|
|
86
|
+
|
|
87
|
+
// Output blank line.
|
|
88
|
+
console.log();
|
|
89
|
+
console.log(' run the app:');
|
|
90
|
+
if (launchedFromCmd())
|
|
91
|
+
console.log(` ${prompt} SET DEBUG=${appName}:* & npm start`);
|
|
92
|
+
else
|
|
93
|
+
console.log(` ${prompt} DEBUG=${appName}:* npm start`);
|
|
94
|
+
|
|
95
|
+
// Output blank line.
|
|
96
|
+
console.log();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get the application name based on the installation directory.
|
|
101
|
+
*/
|
|
102
|
+
function getAppName(installDir) {
|
|
103
|
+
return path.basename(installDir)
|
|
104
|
+
.replace(/[^A-Za-z0-9.-]+/g, '-')
|
|
105
|
+
.replace(/^[-_.]+|-+$/g, '')
|
|
106
|
+
.toLowerCase();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Does the installation directory already exist?
|
|
111
|
+
*
|
|
112
|
+
* @param {String} dir
|
|
113
|
+
* @param {Function} fn
|
|
114
|
+
*/
|
|
115
|
+
function existsInstallationDirectory(dir, fn) {
|
|
116
|
+
fs.readdir(dir, (error, files) => {
|
|
117
|
+
if (error && error.code !== 'ENOENT')
|
|
118
|
+
throw error;
|
|
119
|
+
fn(!files || !files.length);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Graceful exit for async STDIO
|
|
125
|
+
*/
|
|
126
|
+
function exit(code) {
|
|
127
|
+
// flush output for Node.js Windows pipe bug
|
|
128
|
+
// https://github.com/joyent/node/issues/6247 is just one bug example
|
|
129
|
+
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
|
|
130
|
+
function done() {
|
|
131
|
+
if (!(draining--))
|
|
132
|
+
_exit(code)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let draining = 0
|
|
136
|
+
const streams = [process.stdout, process.stderr]
|
|
137
|
+
exit.exited = true
|
|
138
|
+
streams.forEach(function(stream) {
|
|
139
|
+
// submit empty write request and wait for completion
|
|
140
|
+
draining += 1;
|
|
141
|
+
stream.write('', done);
|
|
142
|
+
});
|
|
143
|
+
done();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Determine if launched from cmd.exe
|
|
148
|
+
*/
|
|
149
|
+
function launchedFromCmd() {
|
|
150
|
+
return process.platform === 'win32' && process.env._ === undefined
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Compile template.
|
|
155
|
+
*/
|
|
156
|
+
function compile(file, locals) {
|
|
157
|
+
const contents = fs.readFileSync(`${file}.ejs`, 'utf-8');
|
|
158
|
+
const compiled = ejs.render(contents, locals, {escape: util.inspect});
|
|
159
|
+
fs.writeFileSync(file, compiled, {mode: parseInt('0755', 8)})
|
|
160
|
+
console.log(` \x1b[36mcreate\x1b[0m : ${file}`);
|
|
161
|
+
fs.unlinkSync(`${file}.ejs`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Main program.
|
|
166
|
+
*/
|
|
167
|
+
function main() {
|
|
168
|
+
const installDir = program.args.shift() || '.'
|
|
169
|
+
const appName = getAppName(path.resolve(installDir)) || 'myapp'
|
|
170
|
+
existsInstallationDirectory(installDir, notexists => {
|
|
171
|
+
if (notexists || program.force)
|
|
172
|
+
createApplication(appName, installDir);
|
|
173
|
+
else
|
|
174
|
+
confirm('destination is not empty, continue? [y/N] ', ok => {
|
|
175
|
+
if (ok) {
|
|
176
|
+
process.stdin.destroy()
|
|
177
|
+
createApplication(appName, installDir)
|
|
178
|
+
} else {
|
|
179
|
+
console.error('aborting')
|
|
180
|
+
exit(1)
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Re-assign process.exit because of commander
|
|
187
|
+
|
|
188
|
+
// TODO: Switch to a different command framework
|
|
189
|
+
const _exit = process.exit;
|
|
190
|
+
process.exit = exit;
|
|
191
|
+
|
|
192
|
+
// CLI
|
|
193
|
+
around(program, 'optionMissingArgument', function(fn, args) {
|
|
194
|
+
program.outputHelp();
|
|
195
|
+
fn.apply(this, args);
|
|
196
|
+
return {args: [], unknown: []};
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
before(program, 'outputHelp', function() {
|
|
200
|
+
// track if help was shown for unknown option
|
|
201
|
+
this._helpShown = true;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
before(program, 'unknownOption', function() {
|
|
205
|
+
// allow unknown options if help was shown, to prevent trailing error
|
|
206
|
+
this._allowUnknownOption = this._helpShown;
|
|
207
|
+
|
|
208
|
+
// show help if not yet shown
|
|
209
|
+
if (!this._helpShown)
|
|
210
|
+
program.outputHelp();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
program
|
|
214
|
+
.name('express-sweet')
|
|
215
|
+
.version(version, ' --version')
|
|
216
|
+
.usage('[options] [dir]')
|
|
217
|
+
.option('-o, --output <output>', 'add output <module> support (esm|cjs) (defaults to cjs)')
|
|
218
|
+
.option('-p, --port <port>', 'application listening port', value => parseInt(value, 10), 3000)
|
|
219
|
+
.option('-f, --force', 'force on non-empty directory')
|
|
220
|
+
.parse(process.argv);
|
|
221
|
+
|
|
222
|
+
if (!exit.exited)
|
|
222
223
|
main();
|
package/package.json
CHANGED
|
@@ -66,6 +66,7 @@ module.exports = {
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* URL to redirect after log off, defaults to `/login`.
|
|
69
|
+
* @type {string|((req: express.Request, res: express.Response) => string)}
|
|
69
70
|
* @example
|
|
70
71
|
* // Set the URL to redirect to in case of login failure as a string.
|
|
71
72
|
* failure_redirect: '/login',
|
|
@@ -75,8 +76,6 @@ module.exports = {
|
|
|
75
76
|
* // If the role stored in the cookie is admin, redirect to the admin login screen.
|
|
76
77
|
* return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
|
|
77
78
|
* },
|
|
78
|
-
*
|
|
79
|
-
* @type {string|((req: express.Request, res: express.Response) => string)}
|
|
80
79
|
*/
|
|
81
80
|
failure_redirect: '/login',
|
|
82
81
|
|
|
@@ -38,12 +38,11 @@ module.exports = {
|
|
|
38
38
|
* This is a hook that rewrites the base URL.
|
|
39
39
|
* If you want to rewrite the app.locals.baseUrl property and the view's baseUrl variable, use this hook to return a new base URL.
|
|
40
40
|
* The default value is the referrer's origin (eg https://example.com).
|
|
41
|
+
* @type {(baseUrl: string): string}
|
|
41
42
|
* @example
|
|
42
43
|
* rewrite_base_url: baseUrl => {
|
|
43
44
|
* return `${baseUrl}/admin`;
|
|
44
45
|
* }
|
|
45
|
-
*
|
|
46
|
-
* @type {(baseUrl: string): string}
|
|
47
46
|
*/
|
|
48
47
|
rewrite_base_url: baseUrl => {
|
|
49
48
|
return baseUrl;
|
|
@@ -37,13 +37,16 @@ module.exports = {
|
|
|
37
37
|
/**
|
|
38
38
|
* Hook function just before the view is rendered.
|
|
39
39
|
* For example, you can set your own local variables that can be used within the view.
|
|
40
|
+
* @type {(res: express.Response) => Promise<void>|void}
|
|
40
41
|
* @example
|
|
41
42
|
* // The message set here can be referenced in the view as {{message}}.
|
|
42
43
|
* beforeRender: (req, res) => {
|
|
43
44
|
* res.locals.extra = 'Extra';
|
|
44
45
|
* }
|
|
45
|
-
*
|
|
46
|
-
* @type {(res: express.Response) => Promise<void>|void}
|
|
47
46
|
*/
|
|
48
|
-
beforeRender: (req, res) => {
|
|
47
|
+
beforeRender: (req, res) => {
|
|
48
|
+
// Set the initial sidebar state from the cookie, defaulting to 'off'.
|
|
49
|
+
res.locals.sidebar_minimize_state = req.cookies.sidebar_minimize_state || 'off';
|
|
50
|
+
// console.log('Sidebar minimize state from cookie:', req.cookies.sidebar_minimize_state);
|
|
51
|
+
}
|
|
49
52
|
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
upstream <%- name %>-upstream {
|
|
2
|
-
# ip_hash;
|
|
3
|
-
server 127.0.0.1:<%- port %>;
|
|
4
|
-
# keepalive 64;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
server {
|
|
8
|
-
listen 80;
|
|
9
|
-
server_name <your host name>;
|
|
10
|
-
charset UTF-8;
|
|
11
|
-
access_log /var/log/nginx/<%- name %>.access.log main;
|
|
12
|
-
error_log /var/log/nginx/<%- name %>.error.log warn;
|
|
13
|
-
|
|
14
|
-
# Hide PHP version and web server software name
|
|
15
|
-
server_tokens off;
|
|
16
|
-
|
|
17
|
-
# Proxy to nodejs app
|
|
18
|
-
location / {
|
|
19
|
-
#proxy_set_header X-Forwarded-Proto https;
|
|
20
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
21
|
-
proxy_set_header X-Real-IP $remote_addr;
|
|
22
|
-
proxy_set_header Host $http_host;
|
|
23
|
-
|
|
24
|
-
# Buffering
|
|
25
|
-
client_max_body_size 100m;
|
|
26
|
-
client_body_buffer_size 100m;
|
|
27
|
-
proxy_buffers 8 10m;
|
|
28
|
-
proxy_buffer_size 10m;
|
|
29
|
-
proxy_busy_buffers_size 10m;
|
|
30
|
-
|
|
31
|
-
# Disable caching
|
|
32
|
-
set $do_not_cache 1;
|
|
33
|
-
proxy_no_cache $do_not_cache;
|
|
34
|
-
proxy_cache_bypass $do_not_cache;
|
|
35
|
-
sendfile off;
|
|
36
|
-
|
|
37
|
-
# Enable WebSockets
|
|
38
|
-
proxy_http_version 1.1;
|
|
39
|
-
proxy_set_header Upgrade $http_upgrade;
|
|
40
|
-
proxy_set_header Connection "upgrade";
|
|
41
|
-
|
|
42
|
-
# Send a request to an Express application
|
|
43
|
-
proxy_redirect off;
|
|
44
|
-
proxy_read_timeout 1m;
|
|
45
|
-
proxy_connect_timeout 1m;
|
|
46
|
-
proxy_pass http://<%- name %>-upstream;
|
|
47
|
-
}
|
|
1
|
+
upstream <%- name %>-upstream {
|
|
2
|
+
# ip_hash;
|
|
3
|
+
server 127.0.0.1:<%- port %>;
|
|
4
|
+
# keepalive 64;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
server {
|
|
8
|
+
listen 80;
|
|
9
|
+
server_name <your host name>;
|
|
10
|
+
charset UTF-8;
|
|
11
|
+
access_log /var/log/nginx/<%- name %>.access.log main;
|
|
12
|
+
error_log /var/log/nginx/<%- name %>.error.log warn;
|
|
13
|
+
|
|
14
|
+
# Hide PHP version and web server software name
|
|
15
|
+
server_tokens off;
|
|
16
|
+
|
|
17
|
+
# Proxy to nodejs app
|
|
18
|
+
location / {
|
|
19
|
+
#proxy_set_header X-Forwarded-Proto https;
|
|
20
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
21
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
22
|
+
proxy_set_header Host $http_host;
|
|
23
|
+
|
|
24
|
+
# Buffering
|
|
25
|
+
client_max_body_size 100m;
|
|
26
|
+
client_body_buffer_size 100m;
|
|
27
|
+
proxy_buffers 8 10m;
|
|
28
|
+
proxy_buffer_size 10m;
|
|
29
|
+
proxy_busy_buffers_size 10m;
|
|
30
|
+
|
|
31
|
+
# Disable caching
|
|
32
|
+
set $do_not_cache 1;
|
|
33
|
+
proxy_no_cache $do_not_cache;
|
|
34
|
+
proxy_cache_bypass $do_not_cache;
|
|
35
|
+
sendfile off;
|
|
36
|
+
|
|
37
|
+
# Enable WebSockets
|
|
38
|
+
proxy_http_version 1.1;
|
|
39
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
40
|
+
proxy_set_header Connection "upgrade";
|
|
41
|
+
|
|
42
|
+
# Send a request to an Express application
|
|
43
|
+
proxy_redirect off;
|
|
44
|
+
proxy_read_timeout 1m;
|
|
45
|
+
proxy_connect_timeout 1m;
|
|
46
|
+
proxy_pass http://<%- name %>-upstream;
|
|
47
|
+
}
|
|
48
48
|
}
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
data-kt-app-sidebar-push-toolbar="true"
|
|
34
34
|
data-kt-app-sidebar-push-footer="true"
|
|
35
35
|
data-kt-app-toolbar-enabled="true"
|
|
36
|
+
{{#if (eq sidebar_minimize_state "on")}}
|
|
37
|
+
data-kt-app-sidebar-minimize="on"
|
|
38
|
+
{{/if}}
|
|
36
39
|
class="app-default"
|
|
37
40
|
{{else}}
|
|
38
41
|
class="app-blank"
|
|
@@ -283,7 +286,13 @@
|
|
|
283
286
|
4. Add "active" class to to sidebar toggle element with "kt_app_sidebar_toggle" id.
|
|
284
287
|
}
|
|
285
288
|
-->
|
|
286
|
-
<div
|
|
289
|
+
<div
|
|
290
|
+
id="kt_app_sidebar_toggle"
|
|
291
|
+
class="app-sidebar-toggle btn btn-icon btn-shadow btn-sm btn-color-muted btn-active-color-primary body-bg h-30px w-30px position-absolute top-50 start-100 translate-middle rotate {{#if (eq sidebar_minimize_state "on")}}active{{/if}}"
|
|
292
|
+
data-kt-toggle="true"
|
|
293
|
+
data-kt-toggle-state="active"
|
|
294
|
+
data-kt-toggle-target="body"
|
|
295
|
+
data-kt-toggle-name="app-sidebar-minimize">
|
|
287
296
|
<i class="ki-duotone ki-double-left fs-2 rotate-180">
|
|
288
297
|
<span class="path1"></span>
|
|
289
298
|
<span class="path2"></span>
|
|
@@ -66,6 +66,7 @@ export default {
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* URL to redirect after log off, defaults to `/login`.
|
|
69
|
+
* @type {string|((req: express.Request, res: express.Response) => string)}
|
|
69
70
|
* @example
|
|
70
71
|
* // Set the URL to redirect to in case of login failure as a string.
|
|
71
72
|
* failure_redirect: '/login',
|
|
@@ -75,8 +76,6 @@ export default {
|
|
|
75
76
|
* // If the role stored in the cookie is admin, redirect to the admin login screen.
|
|
76
77
|
* return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
|
|
77
78
|
* },
|
|
78
|
-
*
|
|
79
|
-
* @type {string|((req: express.Request, res: express.Response) => string)}
|
|
80
79
|
*/
|
|
81
80
|
failure_redirect: '/login',
|
|
82
81
|
|
|
@@ -38,12 +38,11 @@ export default {
|
|
|
38
38
|
* This is a hook that rewrites the base URL.
|
|
39
39
|
* If you want to rewrite the app.locals.baseUrl property and the view's baseUrl variable, use this hook to return a new base URL.
|
|
40
40
|
* The default value is the referrer's origin (eg https://example.com).
|
|
41
|
+
* @type {(baseUrl: string): string}
|
|
41
42
|
* @example
|
|
42
43
|
* rewrite_base_url: baseUrl => {
|
|
43
44
|
* return `${baseUrl}/admin`;
|
|
44
45
|
* }
|
|
45
|
-
*
|
|
46
|
-
* @type {(baseUrl: string): string}
|
|
47
46
|
*/
|
|
48
47
|
rewrite_base_url: baseUrl => {
|
|
49
48
|
return baseUrl;
|
|
@@ -37,13 +37,16 @@ export default {
|
|
|
37
37
|
/**
|
|
38
38
|
* Hook function just before the view is rendered.
|
|
39
39
|
* For example, you can set your own local variables that can be used within the view.
|
|
40
|
+
* @type {(res: express.Response) => Promise<void>|void}
|
|
40
41
|
* @example
|
|
41
42
|
* // The message set here can be referenced in the view as {{message}}.
|
|
42
43
|
* beforeRender: (req, res) => {
|
|
43
44
|
* res.locals.extra = 'Extra';
|
|
44
45
|
* }
|
|
45
|
-
*
|
|
46
|
-
* @type {(res: express.Response) => Promise<void>|void}
|
|
47
46
|
*/
|
|
48
|
-
beforeRender: (req, res) => {
|
|
47
|
+
beforeRender: (req, res) => {
|
|
48
|
+
// Set the initial sidebar state from the cookie, defaulting to 'off'.
|
|
49
|
+
res.locals.sidebar_minimize_state = req.cookies.sidebar_minimize_state || 'off';
|
|
50
|
+
// console.log('Sidebar minimize state from cookie:', req.cookies.sidebar_minimize_state);
|
|
51
|
+
}
|
|
49
52
|
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
upstream <%- name %>-upstream {
|
|
2
|
-
# ip_hash;
|
|
3
|
-
server 127.0.0.1:<%- port %>;
|
|
4
|
-
# keepalive 64;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
server {
|
|
8
|
-
listen 80;
|
|
9
|
-
server_name <your host name>;
|
|
10
|
-
charset UTF-8;
|
|
11
|
-
access_log /var/log/nginx/<%- name %>.access.log main;
|
|
12
|
-
error_log /var/log/nginx/<%- name %>.error.log warn;
|
|
13
|
-
|
|
14
|
-
# Hide PHP version and web server software name
|
|
15
|
-
server_tokens off;
|
|
16
|
-
|
|
17
|
-
# Proxy to nodejs app
|
|
18
|
-
location / {
|
|
19
|
-
#proxy_set_header X-Forwarded-Proto https;
|
|
20
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
21
|
-
proxy_set_header X-Real-IP $remote_addr;
|
|
22
|
-
proxy_set_header Host $http_host;
|
|
23
|
-
|
|
24
|
-
# Buffering
|
|
25
|
-
client_max_body_size 100m;
|
|
26
|
-
client_body_buffer_size 100m;
|
|
27
|
-
proxy_buffers 8 10m;
|
|
28
|
-
proxy_buffer_size 10m;
|
|
29
|
-
proxy_busy_buffers_size 10m;
|
|
30
|
-
|
|
31
|
-
# Disable caching
|
|
32
|
-
set $do_not_cache 1;
|
|
33
|
-
proxy_no_cache $do_not_cache;
|
|
34
|
-
proxy_cache_bypass $do_not_cache;
|
|
35
|
-
sendfile off;
|
|
36
|
-
|
|
37
|
-
# Enable WebSockets
|
|
38
|
-
proxy_http_version 1.1;
|
|
39
|
-
proxy_set_header Upgrade $http_upgrade;
|
|
40
|
-
proxy_set_header Connection "upgrade";
|
|
41
|
-
|
|
42
|
-
# Send a request to an Express application
|
|
43
|
-
proxy_redirect off;
|
|
44
|
-
proxy_read_timeout 1m;
|
|
45
|
-
proxy_connect_timeout 1m;
|
|
46
|
-
proxy_pass http://<%- name %>-upstream;
|
|
47
|
-
}
|
|
1
|
+
upstream <%- name %>-upstream {
|
|
2
|
+
# ip_hash;
|
|
3
|
+
server 127.0.0.1:<%- port %>;
|
|
4
|
+
# keepalive 64;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
server {
|
|
8
|
+
listen 80;
|
|
9
|
+
server_name <your host name>;
|
|
10
|
+
charset UTF-8;
|
|
11
|
+
access_log /var/log/nginx/<%- name %>.access.log main;
|
|
12
|
+
error_log /var/log/nginx/<%- name %>.error.log warn;
|
|
13
|
+
|
|
14
|
+
# Hide PHP version and web server software name
|
|
15
|
+
server_tokens off;
|
|
16
|
+
|
|
17
|
+
# Proxy to nodejs app
|
|
18
|
+
location / {
|
|
19
|
+
#proxy_set_header X-Forwarded-Proto https;
|
|
20
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
21
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
22
|
+
proxy_set_header Host $http_host;
|
|
23
|
+
|
|
24
|
+
# Buffering
|
|
25
|
+
client_max_body_size 100m;
|
|
26
|
+
client_body_buffer_size 100m;
|
|
27
|
+
proxy_buffers 8 10m;
|
|
28
|
+
proxy_buffer_size 10m;
|
|
29
|
+
proxy_busy_buffers_size 10m;
|
|
30
|
+
|
|
31
|
+
# Disable caching
|
|
32
|
+
set $do_not_cache 1;
|
|
33
|
+
proxy_no_cache $do_not_cache;
|
|
34
|
+
proxy_cache_bypass $do_not_cache;
|
|
35
|
+
sendfile off;
|
|
36
|
+
|
|
37
|
+
# Enable WebSockets
|
|
38
|
+
proxy_http_version 1.1;
|
|
39
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
40
|
+
proxy_set_header Connection "upgrade";
|
|
41
|
+
|
|
42
|
+
# Send a request to an Express application
|
|
43
|
+
proxy_redirect off;
|
|
44
|
+
proxy_read_timeout 1m;
|
|
45
|
+
proxy_connect_timeout 1m;
|
|
46
|
+
proxy_pass http://<%- name %>-upstream;
|
|
47
|
+
}
|
|
48
48
|
}
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
"name": "<%- name %>",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"imports": {
|
|
6
|
+
"#~/*": "./*"
|
|
7
|
+
},
|
|
5
8
|
"scripts": {
|
|
6
9
|
"start": "nodemon --ignore client/ --ignore public/ --ignore views/ bin/www",
|
|
7
|
-
"//start": "pm2 start ecosystem.config.
|
|
8
|
-
"//restart": "pm2 restart ecosystem.config.
|
|
9
|
-
"//stop": "pm2 stop ecosystem.config.
|
|
10
|
+
"//start": "pm2 start ecosystem.config.cjs",
|
|
11
|
+
"//restart": "pm2 restart ecosystem.config.cjs",
|
|
12
|
+
"//stop": "pm2 stop ecosystem.config.cjs"
|
|
10
13
|
},
|
|
11
14
|
"dependencies": {
|
|
12
15
|
"debug": "~2.6.9",
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
data-kt-app-sidebar-push-toolbar="true"
|
|
34
34
|
data-kt-app-sidebar-push-footer="true"
|
|
35
35
|
data-kt-app-toolbar-enabled="true"
|
|
36
|
+
{{#if (eq sidebar_minimize_state "on")}}
|
|
37
|
+
data-kt-app-sidebar-minimize="on"
|
|
38
|
+
{{/if}}
|
|
36
39
|
class="app-default"
|
|
37
40
|
{{else}}
|
|
38
41
|
class="app-blank"
|
|
@@ -283,7 +286,13 @@
|
|
|
283
286
|
4. Add "active" class to to sidebar toggle element with "kt_app_sidebar_toggle" id.
|
|
284
287
|
}
|
|
285
288
|
-->
|
|
286
|
-
<div
|
|
289
|
+
<div
|
|
290
|
+
id="kt_app_sidebar_toggle"
|
|
291
|
+
class="app-sidebar-toggle btn btn-icon btn-shadow btn-sm btn-color-muted btn-active-color-primary body-bg h-30px w-30px position-absolute top-50 start-100 translate-middle rotate {{#if (eq sidebar_minimize_state "on")}}active{{/if}}"
|
|
292
|
+
data-kt-toggle="true"
|
|
293
|
+
data-kt-toggle-state="active"
|
|
294
|
+
data-kt-toggle-target="body"
|
|
295
|
+
data-kt-toggle-name="app-sidebar-minimize">
|
|
287
296
|
<i class="ki-duotone ki-double-left fs-2 rotate-180">
|
|
288
297
|
<span class="path1"></span>
|
|
289
298
|
<span class="path2"></span>
|