express-sweet-generator 2.0.10 → 2.0.11

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2024 Takuya Motoshima
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
 
@@ -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
- // Copy nginx.sample.conf.
64
- compile(path.join(installDir, 'nginx.sample.conf'), {name: appName, port});
65
-
66
- // Copy package.json.
67
- compile(path.join(installDir, 'package.json'), {name: appName});
68
-
69
- // Copy the front-end module (template/client) to the installation directory.
70
- const templateClientDir = path.join(__dirname, '../templates/client');
71
- fs.copySync(templateClientDir, `${installDir.replace(/\/$/, '')}/client`);
72
-
73
- const prompt = launchedFromCmd() ? '>' : '$'
74
- if (installDir !== '.') {
75
- // Output blank line.
76
- console.log();
77
- console.log(' change directory:');
78
- console.log(` ${prompt} cd ${installDir}`);
79
- }
80
-
81
- // Output blank line.
82
- console.log();
83
- console.log(' install dependencies:');
84
- console.log(` ${prompt} npm install`);
85
-
86
- // Output blank line.
87
- console.log();
88
- console.log(' run the app:');
89
- if (launchedFromCmd())
90
- console.log(` ${prompt} SET DEBUG=${appName}:* & npm start`);
91
- else
92
- console.log(` ${prompt} DEBUG=${appName}:* npm start`);
93
-
94
- // Output blank line.
95
- console.log();
96
- }
97
-
98
- /**
99
- * Get the application name based on the installation directory.
100
- */
101
- function getAppName(installDir) {
102
- return path.basename(installDir)
103
- .replace(/[^A-Za-z0-9.-]+/g, '-')
104
- .replace(/^[-_.]+|-+$/g, '')
105
- .toLowerCase();
106
- }
107
-
108
- /**
109
- * Does the installation directory already exist?
110
- *
111
- * @param {String} dir
112
- * @param {Function} fn
113
- */
114
- function existsInstallationDirectory(dir, fn) {
115
- fs.readdir(dir, (error, files) => {
116
- if (error && error.code !== 'ENOENT')
117
- throw error;
118
- fn(!files || !files.length);
119
- });
120
- }
121
-
122
- /**
123
- * Graceful exit for async STDIO
124
- */
125
- function exit(code) {
126
- // flush output for Node.js Windows pipe bug
127
- // https://github.com/joyent/node/issues/6247 is just one bug example
128
- // https://github.com/visionmedia/mocha/issues/333 has a good discussion
129
- function done() {
130
- if (!(draining--))
131
- _exit(code)
132
- }
133
-
134
- let draining = 0
135
- const streams = [process.stdout, process.stderr]
136
- exit.exited = true
137
- streams.forEach(function(stream) {
138
- // submit empty write request and wait for completion
139
- draining += 1;
140
- stream.write('', done);
141
- });
142
- done();
143
- }
144
-
145
- /**
146
- * Determine if launched from cmd.exe
147
- */
148
- function launchedFromCmd() {
149
- return process.platform === 'win32' && process.env._ === undefined
150
- }
151
-
152
- /**
153
- * Compile template.
154
- */
155
- function compile(file, locals) {
156
- const contents = fs.readFileSync(`${file}.ejs`, 'utf-8');
157
- const compiled = ejs.render(contents, locals, {escape: util.inspect});
158
- fs.writeFileSync(file, compiled, {mode: parseInt('0755', 8)})
159
- console.log(` \x1b[36mcreate\x1b[0m : ${file}`);
160
- fs.unlinkSync(`${file}.ejs`);
161
- }
162
-
163
- /**
164
- * Main program.
165
- */
166
- function main() {
167
- const installDir = program.args.shift() || '.'
168
- const appName = getAppName(path.resolve(installDir)) || 'myapp'
169
- existsInstallationDirectory(installDir, notexists => {
170
- if (notexists || program.force)
171
- createApplication(appName, installDir);
172
- else
173
- confirm('destination is not empty, continue? [y/N] ', ok => {
174
- if (ok) {
175
- process.stdin.destroy()
176
- createApplication(appName, installDir)
177
- } else {
178
- console.error('aborting')
179
- exit(1)
180
- }
181
- })
182
- })
183
- }
184
-
185
- // Re-assign process.exit because of commander
186
-
187
- // TODO: Switch to a different command framework
188
- const _exit = process.exit;
189
- process.exit = exit;
190
-
191
- // CLI
192
- around(program, 'optionMissingArgument', function(fn, args) {
193
- program.outputHelp();
194
- fn.apply(this, args);
195
- return {args: [], unknown: []};
196
- });
197
-
198
- before(program, 'outputHelp', function() {
199
- // track if help was shown for unknown option
200
- this._helpShown = true;
201
- });
202
-
203
- before(program, 'unknownOption', function() {
204
- // allow unknown options if help was shown, to prevent trailing error
205
- this._allowUnknownOption = this._helpShown;
206
-
207
- // show help if not yet shown
208
- if (!this._helpShown)
209
- program.outputHelp();
210
- });
211
-
212
- program
213
- .name('express-sweet')
214
- .version(version, ' --version')
215
- .usage('[options] [dir]')
216
- .option('-o, --output <output>', 'add output <module> support (esm|cjs) (defaults to cjs)')
217
- .option('-p, --port <port>', 'application listening port', value => parseInt(value, 10), 3000)
218
- .option('-f, --force', 'force on non-empty directory')
219
- .parse(process.argv);
220
-
221
- if (!exit.exited)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "EXPRESS SWEET application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
@@ -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,12 @@ 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
47
  beforeRender: (req, res) => {}
49
48
  }
@@ -17,6 +17,7 @@ module.exports = {
17
17
  followSymlinks: false,
18
18
  usePolling: true
19
19
  },
20
+ log_date_format: 'YYYY-MM-DD HH:mm:ss',
20
21
  env: {
21
22
  NODE_ENV: 'development',
22
23
  PORT
@@ -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
  }
@@ -59,6 +59,9 @@ module.exports = {
59
59
  }
60
60
  ]
61
61
  },
62
+ experiments: {
63
+ topLevelAwait: true,
64
+ },
62
65
  optimization: {
63
66
  minimizer: [
64
67
  new CssMinimizerPlugin()
@@ -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,12 @@ 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
47
  beforeRender: (req, res) => {}
49
48
  }
@@ -17,6 +17,7 @@ module.exports = {
17
17
  followSymlinks: false,
18
18
  usePolling: true
19
19
  },
20
+ log_date_format: 'YYYY-MM-DD HH:mm:ss',
20
21
  env: {
21
22
  NODE_ENV: 'development',
22
23
  PORT
@@ -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.js",
8
- "//restart": "pm2 restart ecosystem.config.js",
9
- "//stop": "pm2 stop ecosystem.config.js"
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",