1
0
Fork 0
forked from svrjs/svrjs

Compare commits

..

605 commits
stable ... main

Author SHA1 Message Date
1174a348b6 refactor: use config.wwwroot instead of current working directory as a webroot in internal code 2024-11-10 12:14:55 +01:00
847fb46f07 build: don't create the "out" directory when building for development 2024-11-09 20:21:42 +01:00
11e99ead1c build: fix the development build script by add the ready handler for chokidar watcher 2024-11-09 13:33:17 +01:00
5a0ea4007e feat: add options related to disabling configuration file saving, and use them in the "dev" script 2024-11-09 13:31:31 +01:00
8e1ea9e5bc build: add rebuilding SVR.JS when the source code changes when the "dev" script is executed 2024-11-09 13:20:02 +01:00
bbd1c88016 docs: update README.md 2024-11-09 12:15:07 +01:00
12f2109ad9 chore: update dependencies to latest versions 2024-11-01 09:40:56 +01:00
ad23033b15 feat: add support for Deno 2 for additional SVR.JS utilities 2024-10-19 07:16:02 +02:00
38cf8bb68d fix: fix the cluster limit of one process for Deno with shimmed clustering module 2024-10-18 21:01:51 +02:00
63d3f5df32 fix: fix Deno inconsistencies regarding HTTP status code texts 2024-10-18 20:21:01 +02:00
ad0417b468 fix: add notice about Deno support being experimental 2024-10-18 20:15:13 +02:00
648cf488d9 chore: add a notice about the cluster shim being used for Deno in index.js file 2024-10-18 20:09:42 +02:00
b1a40e7a20 chore: rename the cluster shim method and function, because it's also for Deno 2, not just for Bun 2024-10-18 20:08:52 +02:00
9abb89d560 feat: add support for Deno 2 2024-10-18 20:05:02 +02:00
2f475b4066 fix: fix a bug with 497, 598, and 599 status code HTTP responses 2024-10-15 18:23:09 +02:00
d7b5d0af44 docs: change documentation URL in README 2024-10-02 06:10:56 +02:00
ff15ec542e fix: fix a bug with no request ID shown for multiline log entries for HTTP requests 2024-09-25 15:41:39 +02:00
070f60f7e3 docs: update file structure in README 2024-09-20 07:16:49 +02:00
350496f57a style: enforce the new Prettier rules on the build script 2024-09-20 06:37:14 +02:00
f01d5d5b1e refactor: move SVR.JS logo for the log viewer to src/res/logo.js file 2024-09-20 06:36:37 +02:00
37df85d84a fix: remove unused "tar" dependency from the extraction script 2024-09-20 06:35:17 +02:00
147c7c5d03 build: move utils/ directory to src/extraScripts/ 2024-09-20 06:27:28 +02:00
efdf6f1551 build: enable bundling for utility scripts 2024-09-20 06:22:04 +02:00
e474361673 fix: update the documentation URL 2024-09-14 15:48:08 +02:00
b6f6be8d43 chore: update dependencies to latest versions 2024-09-13 05:49:19 +02:00
5827d88392 chore: update dependencies to latest versions 2024-09-12 16:20:37 +02:00
b5edc0a5dd feat: change the default page CSS to match the new redesigned SVR.JS website 2024-09-11 05:51:12 +02:00
75108c7760 fix: change the code font for index, tests and licenses pages 2024-09-11 05:41:44 +02:00
1637e9dfcf feat: redesign index, tests and licenses pages 2024-09-11 05:39:13 +02:00
58d252defa test: rename web root postfixes middleware test suite to match the corresponding middleware file 2024-09-05 18:50:35 +02:00
645223451a refactor: move printing the command line usage to a separate function 2024-09-02 18:07:07 +02:00
fe6853524e test: mock "path" module in forbidden path utility function unit tests 2024-09-02 13:08:05 +02:00
0fe9a505a6 chore: ignore more OS-specific files and temporary editor files 2024-09-02 08:00:50 +02:00
dad4496488 docs: update file structure in README.md 2024-09-02 07:42:28 +02:00
ea8f17eb7d build: configure lint-staged to only lint files from tests, src, and utils directory 2024-09-01 22:18:59 +02:00
7f1dd091c0 chore: remove .eslintcache 2024-09-01 22:07:56 +02:00
1309f91e90 chore: ignore .eslintcache 2024-09-01 22:03:32 +02:00
0dea0fa4b4 build: make the commit-msg Git hook executable 2024-09-01 22:02:31 +02:00
f287289af3 build: move lint-staged configuration from package.json to separate configuration file 2024-09-01 22:01:49 +02:00
72b803de4b build: add lint-staged and update Git hooks 2024-09-01 21:58:58 +02:00
c2eed2870d style: style the code according to new Prettier rules 2024-09-01 21:54:42 +02:00
48b112f98b build: add Prettier configuration 2024-09-01 21:53:53 +02:00
896d3ee1ff build: add commitizen and "cz" script 2024-09-01 21:43:19 +02:00
d555b2af80 build: add husky and commitlint for commit validation 2024-09-01 21:39:58 +02:00
ae04419988 chore: Update dependencies 2024-09-01 19:33:47 +02:00
5570042732 Remove unnecessary mock implementations and update web root prefixes middleware test description 2024-09-01 14:17:06 +02:00
087eff332f Change the link to GitHub repository in README.md to point to the "next" branch 2024-09-01 12:24:39 +02:00
5049d22153 Temporarily change the documentation URL in the "Documentation" badge in README.md to tentative documentation URL 2024-09-01 10:07:23 +02:00
519c80f397 Convert one more string to template string 2024-09-01 09:51:29 +02:00
39a96cb339 Add link to GitHub repository to GitHub badge in README.md 2024-09-01 09:45:18 +02:00
cfe77b090c Add badges to README.md 2024-09-01 09:42:55 +02:00
99a42cc119 Add dots in README.md 2024-09-01 09:22:15 +02:00
ead2156af0 Update .gitignore 2024-09-01 09:09:16 +02:00
de7d804ca0 Lint out the static file serving and directory listing middleware test script 2024-08-31 20:50:10 +02:00
53dac33694 Add static file serving test 2024-08-31 20:48:55 +02:00
ce9550cc39 Add ".js" extension to one of the requires to tests for blocklist middleware 2024-08-31 17:28:14 +02:00
b6f17d2af4 Change the level of headings in Features section in README.md 2024-08-31 15:31:30 +02:00
65a3f373f0 Format npm scripts section in README.md 2024-08-31 14:29:12 +02:00
8a890bf4ea Open SVR.JS website in a new tab, when SVR.JS logo is clicked in README.md 2024-08-31 14:27:05 +02:00
5c96f87e7c Adjust the width of the SVR.JS logo in README.md 2024-08-31 14:18:45 +02:00
c35d913410 Change logo.png to one with "SVR.JS" name, adjust index.ejs for the new logo file, and adjust README.md 2024-08-31 14:15:55 +02:00
a3f76c56c1 Replace the width attribute with height attribute on logo in README.md 2024-08-31 14:11:44 +02:00
bb274ed045 Make the logo even smaller and remove the <big> tag in README.md 2024-08-31 14:10:53 +02:00
ad0d8b6f3d Replace CSS rule that increases font size with <big> tag in README.md 2024-08-31 14:09:33 +02:00
914fd6612b Make the logo smaller and make the description text bigger in README 2024-08-31 14:08:08 +02:00
70670ee396 Replace external logo with one in the source code 2024-08-31 14:05:41 +02:00
05e3749d53 Replace README with README.md 2024-08-31 14:04:05 +02:00
66fdced1a5 Add thumbnail cache files to .gitignore 2024-08-31 12:08:22 +02:00
4cd5cb4429 Add a newline to .gitignore 2024-08-31 12:04:04 +02:00
bffce3b1db Update README 2024-08-31 11:48:14 +02:00
70bebc1d1e Update dependencies 2024-08-30 22:48:53 +02:00
db238d8b0d Remove lockfiles from .gitignore 2024-08-30 22:21:56 +02:00
fb0da78488 Add test coverage npm script and add "coverage" folder to .gitignore 2024-08-30 22:18:22 +02:00
fdb3e32091 Add package manager lock files to .gitignore 2024-08-30 22:16:57 +02:00
dc71c3a50f Reorganize .gitignore 2024-08-30 22:15:39 +02:00
0450094c68 Add tests for middleware, add ".js" file extensions inside the require functions in tests for utility functions, make error handling in URL rewriting middleware better, and lint out static file serving and directory listing middleware 2024-08-30 22:11:16 +02:00
57ce4018dc Make the build script also pack empty directories into zip file 2024-08-30 08:06:09 +02:00
1444660d19 Fix "NaN" file sizes in directory listings 2024-08-30 06:39:06 +02:00
e293c08592 Convert even more strings to template strings 2024-08-30 06:29:32 +02:00
41901d9a27 Fix the forbidden path checking function, and add test cases, where it would fail before the fix 2024-08-29 19:37:03 +02:00
9f51366515 Simplify ES6-style functions 2024-08-29 19:27:04 +02:00
57d988831f Replace ES6-style functions in server-side JavaScript header with ES5-style functions 2024-08-29 19:19:11 +02:00
0aa4f9df2b Replace ES5-style functions with ES6-style ones 2024-08-29 19:17:28 +02:00
09e33a2265 Lint out the codebase 2024-08-29 19:15:49 +02:00
058c39ab0d Replace __dirname with process.dirname 2024-08-29 19:15:37 +02:00
979a30e938 Replace var's with let's and const's 2024-08-29 19:15:07 +02:00
3b4fd9641c Change blocklist-related commands to use .forEach() function instead of a for loop 2024-08-29 19:05:02 +02:00
7680bb8c27 Improved the test coverage for the URL sanitizer 2024-08-29 13:39:55 +02:00
ce2a73dbd3 Lint out the codebase 2024-08-28 21:46:20 +02:00
9fa194b33d Fix the regular expression in the URL parser 2024-08-28 21:45:36 +02:00
a33a86ee62 Fix bug with "ext" variable passed to .tar.gz mod handler 2024-08-28 18:28:07 +02:00
82b0510774 Optimize URL sanitizer 2024-08-28 16:17:06 +02:00
7fe503c07d Modify package.json - change the lint script (again) 2024-08-28 14:08:38 +02:00
1309e36151 Modify package.json - change the lint script 2024-08-28 14:03:31 +02:00
64b4e056cb Make sizify() function more concise and readable 2024-08-28 13:24:15 +02:00
0318047078 Optimize function related to forbidden path checking and hostname matching 2024-08-28 11:29:54 +02:00
32d29be09f Change the comment above the URL parser function 2024-08-28 11:09:26 +02:00
a4ca117020 Optimize fixNodeMojibakeURL function 2024-08-28 10:52:39 +02:00
486820e1da Converted one more string to template string 2024-08-28 07:35:27 +02:00
17614dc6c7 Clone parsed JSON into process.serverConfig using deepClone() function 2024-08-28 07:27:40 +02:00
5bd369e38d Make deepClone create a null prototype object, and make process.serverConfig a null prototype object. 2024-08-28 07:20:28 +02:00
4b37e08bb5 Optimize deepClone function 2024-08-28 07:14:13 +02:00
fb887e4122 Replace deep clone in getCustomHeaders() function with shallow clone 2024-08-27 23:13:02 +02:00
63633d1de1 Fix the deepClone function 2024-08-27 22:52:36 +02:00
67d9ae524c Optimize deepClone function even more 2024-08-27 22:51:41 +02:00
c73ce5d9f7 Optimize deepClone function and lint out the codebase 2024-08-27 22:49:05 +02:00
47ad7006e9 Replace the iteration with object spread operator 2024-08-27 22:44:21 +02:00
4506d38eac Replace some ES5-style functions with ES6-style ones 2024-08-27 21:53:37 +02:00
12a4bcdc8a Remove unneeded global flag for /\.$/ regular expression 2024-08-27 21:49:06 +02:00
30498263fc Convert a "bytes */" + filelen string to a template string 2024-08-27 21:39:51 +02:00
189fbdc617 Replace Object.assign for arrays with spread operator. 2024-08-27 21:14:58 +02:00
b3cd8d699d Replace shallow cloning with deep cloning when needed. Also create deep cloning JavaScript file and corresponding tests 2024-08-27 21:09:43 +02:00
3eb7f3d4d9 Remove unneeded code 2024-08-27 18:45:56 +02:00
bced5927fe Replace ES5-style function in request handler with ES6-style ones 2024-08-27 18:23:57 +02:00
0c286bda43 Convert "Host name rewritten" message to template string 2024-08-27 18:04:32 +02:00
8589f0a6e4 Changed URL parser from WHATWG to custom one and adapted code accordingly 2024-08-27 18:03:47 +02:00
f247e7a035 Use template strings for user agent information log messages 2024-08-27 17:43:31 +02:00
fc14cfcc1b Remove some empty lines 2024-08-27 16:20:42 +02:00
de08646bba Add unknown licenses, but display "Unknown" as a license type 2024-08-27 16:04:43 +02:00
2783516c86 Don't add unknown licenses to the license page. 2024-08-27 16:02:50 +02:00
f739f5dbbe Fix cluster shim for Bun 2024-08-27 13:57:58 +02:00
9b01d46907 Fix the code for "${name} is running without mods and server-side JavaScript enabled. Web applications may not work as expected" message 2024-08-27 12:16:21 +02:00
ff66e26af0 Change regular expression for createRegex() function 2024-08-27 12:06:23 +02:00
fae1b661ed Fix or ignore all ESLint errors 2024-08-27 11:28:24 +02:00
2872be5b5b Lint out the codebase 2024-08-27 11:03:51 +02:00
7a14e4508c Remove unused "name" constant in noproxyHandler.js 2024-08-27 10:56:49 +02:00
fd5e8ba70e Lint out the codebase 2024-08-27 10:55:24 +02:00
5a3e6765f1 Replace ES5-style functions with ES6-style ones 2024-08-27 10:54:08 +02:00
79f8f2ddf9 Make change log for specific SVR.JS version generated by the build script 2024-08-27 10:49:36 +02:00
1001d6ca41 Change the documentation URL to a tentative one 2024-08-27 10:42:22 +02:00
8de05d87b5 Make the build script not pack two "svr.js" files in the zip file. 2024-08-27 10:38:26 +02:00
6f6fb1f89f Fix 500 Internal Server Error related to URL rewriting 2024-08-27 09:42:06 +02:00
1c94a990fa Use spread operator and change ES5-style functions to ES6-style ones in cluster shim for Bun 2024-08-27 09:31:23 +02:00
4eb2987f01 Fix HTML MIME type in cached requests, regardless of the extension 2024-08-27 09:27:35 +02:00
33fde81ba1 Fix problems with loading .tar.gz mods 2024-08-27 09:15:15 +02:00
9a5d43d129 Change the ASCII logo 2024-08-26 20:01:32 +02:00
4077e6da5e Update package-lock.json 2024-08-26 19:48:03 +02:00
2f783ce1a2 Lint out the codebase 2024-08-26 19:23:52 +02:00
488bee1a95 Replace some strings with template strings 2024-08-26 19:21:52 +02:00
d92fc14991 Remove listenerEmitted flag from HTTP authentication message callback 2024-08-26 17:13:48 +02:00
5672c4a3d5 Fix static file served with wrong MIME type 2024-08-26 13:48:58 +02:00
4299a09c86 Change SVR.JS logo 2024-08-26 13:46:57 +02:00
d1523cea3c Fix the sendStatistics.js file 2024-08-26 13:32:21 +02:00
460829e0be Move code for sending the data to the statistics server to separate utility function 2024-08-26 10:14:21 +02:00
686ec4924e Replace ES5-style functions in code for sending data to a statistics server with ES6-style functions 2024-08-26 10:03:51 +02:00
f403053c44 Add README 2024-08-26 09:59:49 +02:00
9d31eac2f9 Lint out the build script 2024-08-26 09:33:02 +02:00
f074612dda Replace one more "SVR.JS" with reference to svrjs.json file 2024-08-26 09:31:50 +02:00
2e9b0ed1c5 Move default SVR.JS-generate page CSS to the separate file 2024-08-26 09:30:52 +02:00
771327cd8a Add the "folder" directory in "testdir" directory in "assets" directory with a .gitkeep file 2024-08-26 09:23:14 +02:00
5197058e32 Fix the build script and make the output zip file compatible with SVR.JS installer 2024-08-26 09:21:14 +02:00
c4c207cd98 Make the build script transpile the utilities 2024-08-26 08:24:29 +02:00
2a9b47a318 Add NOTES file 2024-08-26 08:06:58 +02:00
1108393b59 Add LICENSE file 2024-08-26 08:00:04 +02:00
25c784181d Don't assign variables to public IP requests 2024-08-26 07:58:37 +02:00
914b38e0b0 Fix 500 Internal Server Error related to HTTP authentication 2024-08-26 07:57:07 +02:00
60b0ea6933 Lint out svrpasswd.js script 2024-08-26 07:38:42 +02:00
34afacd0d2 Replace "config.json" and "./config.json" with __dirname + "/config.json" in svrpasswd.js 2024-08-26 07:38:14 +02:00
7133e750cc Rename utilities directory to utils. 2024-08-26 07:35:01 +02:00
343dce37ec Add utilities to ESLint check list, and lint out the utilities. 2024-08-26 07:34:07 +02:00
26fc7f3b08 Refactor the index.js file 2024-08-26 07:08:31 +02:00
39712a17f4 Lint out the codebase 2024-08-26 07:06:02 +02:00
1fbede69e5 Replace __dirname with process.dirname 2024-08-26 07:05:04 +02:00
9b8ccd31fc Remove commented out required modules 2024-08-26 07:04:47 +02:00
cbf11e7ed6 Replace "SVR.JS" with references to svrjs.json 2024-08-26 07:04:21 +02:00
43235f867a Discard unrecognized control messages (worker side) 2024-08-26 07:02:26 +02:00
233af94d28 Implement sending data to the statistics server 2024-08-26 07:01:52 +02:00
ef78a88a39 Implement listeningMessage() function, around with public IP obtaining 2024-08-26 07:00:08 +02:00
57f9c2ac99 Remove "TODO: configuration from config.json" comment 2024-08-26 06:37:38 +02:00
1403a37dea Remove notifications about broken mods and server-side JavaScript outside the start function 2024-08-26 06:36:57 +02:00
1f043d774a Replace code invoke the start() function with one with error handler 2024-08-26 06:35:25 +02:00
83418dbb10 Remove "TODO: after implementing clustering in new SVR.JS" comment 2024-08-26 06:34:06 +02:00
57bb2293b9 Fix "block" and "unblock" commands 2024-08-26 06:32:54 +02:00
a02e976dfe Added configuration file saving. 2024-08-26 06:26:22 +02:00
87cecd6cf3 Remove more TODO comments 2024-08-26 06:23:24 +02:00
9d1e6e82ba Remove some TODO comments 2024-08-26 06:21:50 +02:00
cc859e0319 Enable saving the configuration file when process is exiting 2024-08-26 06:20:23 +02:00
601eed5f62 Lint out the codebase 2024-08-26 06:19:53 +02:00
a82f5ac010 Discard unrecognized control messages (main-side) 2024-08-26 06:19:27 +02:00
96dfe853d4 Implement configuration file saving interval 2024-08-26 06:17:51 +02:00
ab98415030 Remove commented code snippet that's already in src/handlers/serverErrorHander.js file 2024-08-26 06:12:45 +02:00
662528847a Add termination of unused workers. 2024-08-26 06:11:19 +02:00
083b2794df Uncomment the code related to sending the "stop" command to workers when Ctrl+C is pressed 2024-08-25 20:45:40 +02:00
0eb6cf8c07 Fix --single-threaded flag 2024-08-25 20:38:35 +02:00
fca7fb78d6 Add "restart" command placeholder. 2024-08-25 20:37:25 +02:00
4a528120be Fix 3eacbdb397 commit 2024-08-25 20:21:48 +02:00
3eacbdb397 Add handler for "\x12CLOSE" messages 2024-08-25 20:20:15 +02:00
3de85443d5 Add server console, and fixed listening error message handler 2024-08-25 20:18:35 +02:00
a55b123926 Lint out the codebase 2024-08-25 19:46:17 +02:00
adfd3ff809 Enable hangup check and restart 2024-08-25 19:45:02 +02:00
e85f53197c Add "let" before "i=0" for logo iterative loop 2024-08-25 19:40:27 +02:00
9db7ffdaec Add reqcounterKillReq variable 2024-08-25 19:39:49 +02:00
99583731d9 Move getWorkerCountToFork and forkWorkers functions to global scope 2024-08-25 19:37:22 +02:00
4f565d1550 Add addListenersToWorker() function 2024-08-25 19:35:58 +02:00
a92616b0a4 Partially implemented clustering. 2024-08-25 19:28:20 +02:00
1f5602626a Add stop command 2024-08-25 19:23:01 +02:00
b36a301e03 Add close and open commands. 2024-08-25 19:20:15 +02:00
85debce9c9 Lint out the codebase 2024-08-25 19:17:54 +02:00
0ea53fdf96 Lint out the codebase, add SVRJSFork() function, networking-related code, and ipSubnetUtils.js utility functions file and corresponding unit tests 2024-08-25 19:17:19 +02:00
2c990a6907 Lint out the codebase 2024-08-25 18:59:16 +02:00
2c271bccdc Add portions of real start() function, and logo resource JavaScript file. 2024-08-25 18:57:46 +02:00
54de936aae Lint out the codebase 2024-08-25 18:02:18 +02:00
bdc11fa3dc Replace var's with const's in OCSP stapling handler 2024-08-25 18:02:02 +02:00
9b03abc646 Add OCSP stapling support 2024-08-25 17:59:52 +02:00
95416f4604 Lint out the codebase 2024-08-25 17:58:01 +02:00
58cb60fb8f Change the way of adding process message listeners, and add process message listener to server error handler. 2024-08-25 17:57:23 +02:00
45815957d5 Create the server error handler and temporary startup script. 2024-08-25 17:51:25 +02:00
489ec9741a Add process.serverConfig.productName 2024-08-25 17:15:40 +02:00
67658ad329 Lint out the codebase 2024-08-25 17:15:00 +02:00
eaafa8cc41 Add certificate and SNI loading. 2024-08-25 17:11:31 +02:00
b758e11513 Add secondary HTTP server and handlers for primary HTTP server 2024-08-25 17:04:49 +02:00
7b4612e8b0 Move commands in index.js 2024-08-25 16:51:25 +02:00
98c36d2b64 Add commands 2024-08-25 16:47:26 +02:00
a241af753e Server crashes now results in exit code of 1 if errno is not specified. 2024-08-25 16:35:19 +02:00
984c94cd00 Lint out the codebase 2024-08-25 16:25:25 +02:00
44e4c15b30 Fix parsePostData function in legacy mod wrapper. 2024-08-25 16:24:34 +02:00
21b5f46e9e Add process exit and crash handlers. 2024-08-25 16:23:16 +02:00
6958ec6c94 Remove commented out addMiddleware function. 2024-08-25 15:55:36 +02:00
7d4dcdd2a6 Fix problems executing SVR.JS 2.x and 3.x mods, and server-side JavaScript 2024-08-25 15:53:45 +02:00
6302bb0044 Fix problem with hexstrbase64 2024-08-25 15:50:56 +02:00
8d825403b9 Add default server-side JavaScript from SVR.JS 3.15.6 to assets directory. 2024-08-25 15:48:12 +02:00
f05fb50625 Add support for SVR.JS 2.x and 3.x server-side JavaScript. 2024-08-25 15:47:12 +02:00
23508a5292 Added support for SVR.JS 2.x and 3.x mods. 2024-08-25 15:40:53 +02:00
85e15e0517 Change ESLint configuration to use CommonJS modules instead of ES modules. 2024-08-25 14:27:22 +02:00
eebada191b Lint out the codebase 2024-08-25 14:24:18 +02:00
6461728eee Fix the description for URL parser test suite 2024-08-25 14:14:22 +02:00
88554a05d2 Modify the description for URL parser test suite 2024-08-25 14:13:27 +02:00
2884c33c8c Rename urlParser files to urlParserLegacy 2024-08-25 14:12:13 +02:00
aa4e4d0c15 Add "Load SVR.JS mods as middleware" comment. 2024-08-25 14:05:19 +02:00
9d0a156c46 Add mod loader 2024-08-25 14:02:45 +02:00
ed71618856 Lint out SHA256 function 2024-08-25 13:18:19 +02:00
b5de4b79c5 Make generateServerString() function replace spaces in name property of svrjs.json with dashes. 2024-08-25 13:13:16 +02:00
7decde6b58 Lint out the codebase 2024-08-25 13:10:28 +02:00
fcec27fee1 Replace "SVR.JS" with references to svrjs.json file 2024-08-25 13:09:58 +02:00
04ab80cc95 Lint out the codebase 2024-08-25 12:56:36 +02:00
b79e165bed Change proxy handler to end the socket with 500 Internal Server Error only when it is not destroyed. 2024-08-25 12:55:34 +02:00
5b91c21973 Add CONNECT request (proxy request) handler. 2024-08-25 12:54:36 +02:00
ddae2e468e Fix Cannot assign to "currentMiddleware" because it is a constant error. 2024-08-25 12:38:15 +02:00
4b02efdeba Add proxySafe flag to middleware. 2024-08-25 12:37:14 +02:00
fb7c5ed854 Move core middleware to the request handler. 2024-08-25 12:33:11 +02:00
988ff7c29c Lint out the codebase 2024-08-25 11:57:45 +02:00
314cf247d4 Fix server string not displaying in the bad request response. 2024-08-25 11:55:42 +02:00
60615cdb5a Move handlers to JavaScript files in handler directory. 2024-08-25 11:47:43 +02:00
e9e3bf5377 Fix eslint script to also lint index.js file. 2024-08-25 11:38:11 +02:00
726d161a64 Add client error handler, and lint out index.js 2024-08-25 11:32:03 +02:00
0085ff740d Change reqerrhandler placeholder to emitting clientError event on the server. 2024-08-25 10:57:37 +02:00
478c3002f0 Remove "TODO: default handler" comment 2024-08-25 10:33:29 +02:00
bdd3e56bb1 Make the build script also copy hidden directories in assets directory. 2024-08-25 10:32:08 +02:00
0ceded2256 Add static file serving and directory listing functionality. 2024-08-25 10:23:37 +02:00
b5ad179097 Replace "SVR.JS" in status page with reference to svrjs.json 2024-08-25 09:47:36 +02:00
695816b9d0 Lint out the codebase. 2024-08-25 09:45:42 +02:00
55d5efe54f Add default handler checks, server status page, sizify() utility function, and move counters from core.js middleware to index.js. 2024-08-25 09:44:53 +02:00
8a54834276 Lint out the codebase. 2024-08-25 09:25:06 +02:00
9bb77f9d98 Add more tests for ipBlockList function. 2024-08-25 09:23:55 +02:00
5d463c9f11 Fix a 500 HTTP error code related to URL rewriting functionality. 2024-08-25 09:14:38 +02:00
89e9b35829 Add ipBlockList utility function, blocklist functionality, and read from config.json functionality. 2024-08-25 09:12:39 +02:00
2f836231f4 Do some config.json TODO's 2024-08-25 08:32:49 +02:00
41bea903bb Remove node_modules (they are ignored in .gitignore) 2024-08-25 07:23:45 +02:00
bafc08d965 Lint out the codebase. 2024-08-25 07:17:34 +02:00
5fab894caf Move parts of middleware that checks for forbidden paths to separate utils file, and add tests for them. 2024-08-25 07:13:41 +02:00
983133017f Add some TODO comments for middleware. 2024-08-24 20:47:23 +02:00
e94391f197 Lint out the codebase. 2024-08-24 20:45:17 +02:00
2075d41ab3 Fix URL sanitiation and rewriting-related functions removing query strings and hashes. 2024-08-24 20:44:43 +02:00
3613aa92d2 Add trailing slash redirection middleware. 2024-08-24 20:40:28 +02:00
c1900ee128 Add non-standard codes and HTTP authentication middleware, and SHA256 utility function. 2024-08-24 20:32:06 +02:00
eb0d30f307 Lint out the codebase. 2024-08-24 19:50:01 +02:00
8be7735e71 Refactor code for --reset parameter again. 2024-08-24 19:49:36 +02:00
2e8a4fb042 Refactor command line argument parsing code, and split deleteFolderRecursive function into one JavaScript file. 2024-08-24 19:47:48 +02:00
918c0d3646 Added missing "testdir" directory to assets folder. 2024-08-24 19:43:40 +02:00
07c7199adb Add log, mods, and temp directory creation in output directory 2024-08-24 19:43:02 +02:00
b9bb16b0ed Add command line options 2024-08-24 19:41:13 +02:00
ca5c22c9c3 Move required modules in index.js 2024-08-24 19:30:25 +02:00
11e7247869 Replace __dirname with process.dirname (declared as __dirname in index.js) 2024-08-24 19:29:12 +02:00
24b161b0ed Replace var's with const's in the middleware that checks for forbidden paths. 2024-08-24 17:48:55 +02:00
519988fbdb Lint out the codebase. 2024-08-24 17:46:55 +02:00
67fec5fe98 Add middleware that checks for forbidden paths. Also add some more placeholder config.json variables. 2024-08-24 17:44:25 +02:00
d688166022 Add middleware responsible for setting response headers (res.setHeader function). 2024-08-24 17:32:27 +02:00
f552b34878 Lint out the codebase. 2024-08-24 17:23:06 +02:00
f48125f4f2 Move matchHostname function to separate source file, and add unit tests for the function. 2024-08-24 17:21:09 +02:00
519e68465a Add SVR.JS name and documentation URL to svrjs.json file. 2024-08-24 17:13:59 +02:00
1161256ab9 Create config.generateServerString() function and src/utils/generateServerString.js file. 2024-08-24 17:06:34 +02:00
1a7e602198 Change version from Nightly-GitMain to Nightly-GitNext. 2024-08-24 16:59:05 +02:00
e1b6ca8803 Change serverconsole.js, so it no longer exports the constructor, just serverconsole object. 2024-08-24 16:58:27 +02:00
3a8cdccc0d Replace configJSON with process.serverConfig. 2024-08-24 16:55:44 +02:00
7a658613fe Added process.singleThreaded flag. 2024-08-24 16:54:28 +02:00
a3e4ee2328 Replace some var's with const's in URL rewrite and web root postfix middleware. 2024-08-24 08:24:39 +02:00
2481e3ed58 Add URL rewriting middleware, and lint out some other middleware. 2024-08-24 08:22:49 +02:00
a49dba73fe Lint out the codebase. 2024-08-24 08:07:31 +02:00
1929641ba7 Add web root postfixes middleware 2024-08-24 08:02:11 +02:00
a7acd9e1f4 Replace "callServerError" with "res.error" in the core middleware. 2024-08-23 22:47:27 +02:00
cbd3ab0cd0 Adapted redirectes middleware function to new SVR.JS API. 2024-08-23 22:19:41 +02:00
53024dfdab Added redirects middleware. 2024-08-23 22:13:58 +02:00
0c9013feac Added res.head, res.foot, res.responseWrite, and rejection of expectations. 2024-08-23 22:10:49 +02:00
881502d897 Disable console.log for non-TTY stdout 2024-08-23 21:58:26 +02:00
00d01e7cf5 Replace "var" with "let" in core middleware, and add req.authUser set to null. 2024-08-23 21:46:08 +02:00
0e8b8392a4 Replace the placeholder fromMain with estimated one. 2024-08-23 21:41:31 +02:00
d5c4e9aeaf Fix the baf38ee353 commit. 2024-08-23 21:35:58 +02:00
baf38ee353 Add "throw wwwrootError", for now. 2024-08-23 21:34:58 +02:00
be33f83ed1 Added default config.json setting from SVR.JS 3.x, and fixed core middleware. 2024-08-23 21:33:26 +02:00
2dda7d73ab Replaced responseEnd() function (which doesn't exist) with res.end() function for now 2024-08-23 21:27:36 +02:00
dd344ecca3 Expand core middleware, add URL sanitizer middleware, and add logging to the middleware error handling. 2024-08-23 21:25:23 +02:00
000ae75904 Add middleware functionality. Also replace JSON.parse with JSON.stringify with Object.assign. 2024-08-23 20:43:09 +02:00
ee4c3dcda6 Add some core functionality to SVR.JS 2024-08-23 19:58:15 +02:00
fbdb3f93d4 Add URL sanitizer. Also add eslint-plugin-jest to ESLint configuration. 2024-08-23 17:43:37 +02:00
5171855776 Add more npm scripts. 2024-08-23 17:21:52 +02:00
c9db45c0fe The build script now builds SVR.JS .zip archive. 2024-08-23 17:18:18 +02:00
6564ccbe83 Rewritten SVR.JS from scratch - the build system for the new SVR.JS is set up, but the source is just placeholders. 2024-08-23 17:05:10 +02:00
0e722d8fcf Updated many dependencies and changed files related to licenses accordingly 2024-08-22 12:40:30 +02:00
0ec041617e Update "index.html" file 2024-08-06 16:53:05 +02:00
af02333183 Add the code to send data to the statistics server. 2024-08-06 16:34:13 +02:00
Dorian Niemiec
3661ccb92f
Update main.yml 2024-06-22 09:16:06 +02:00
94f4374718 Git test file removed 2024-06-22 08:27:08 +02:00
e1877c3ea9 Git file test 2024-06-22 08:22:25 +02:00
c05b8f8d00 Lifted PBKDF2 restrictions on Bun 1.1.13 and later. 2024-06-13 15:21:02 +02:00
2c2ca100a4 Lint out unnamed functions 2024-05-30 09:15:11 +02:00
d2e9f73f2f Move worker forking code to separate function. Also cap minimum number of workers to 12 to reduce idle memory usage. 2024-05-30 09:06:01 +02:00
5942f9dbde Fix URL parser even more 2024-05-21 17:26:22 +02:00
6933e3e9ed Fixed bug in the URL parser (URLs with "@" got erroneously "sanitized" to "/") 2024-05-21 17:08:06 +02:00
5781233ff7 Replace "minClusters" and "allClusters" with "minWorkers" and "allWorkers" respectively 2024-05-20 17:34:29 +02:00
fc03b485ef Removed 16 CPU cores cap 2024-05-20 17:29:40 +02:00
2eedf125a8 Combine crash handlers in master process into one function. 2024-05-20 17:27:09 +02:00
8af7f1df99 Improve HTTP partial content request logging 2024-05-13 17:59:48 +02:00
9c82164433 Add checks for zero-length head and foot in static file serving function 2024-05-13 17:56:58 +02:00
0a3371878c Added support for Range requests for HTML files 2024-05-13 17:29:18 +02:00
f3edbcc3f3 Fix the previous commit 2024-05-13 17:01:11 +02:00
6c3a5bd9ee Reduced calls to "mime-types" library 2024-05-13 16:59:41 +02:00
87ba2dd985 Update the design of default HTML pages 2024-05-06 11:55:26 +02:00
01d3a18e01 Correct the CSS for HTML tables 2024-05-06 11:04:05 +02:00
c922ebf1ae Add CSS to default error pages 2024-05-06 11:00:54 +02:00
6b75453cb2 Clean up the code 2024-05-05 22:24:35 +02:00
4453724db7 Partially revert previous commit (add blocking calls back due to degraded performance in Bun) 2024-05-05 22:23:25 +02:00
45d45c41af Remove blocking calls from custom head and custom foot functionality. Also optimize built-in "vres" callbacks. 2024-05-05 22:07:44 +02:00
a1160bd891 Replaced wrapper over WHATWG URL API with custom URL parser 2024-05-05 21:26:13 +02:00
fa64c763bd Fix syntax error 2024-05-03 12:02:18 +02:00
befabe2c9a Remove calls to getCustomHeaders in vres function 2024-05-03 12:01:17 +02:00
1226839163 Revert previous commit 2024-05-01 14:14:12 +02:00
aa6125b891 Move nested functions to the bottom of functions 2024-05-01 14:12:04 +02:00
255963c954 Replaced path.extname function with regex-based custom one. Also remove "pth" variable from static file serving function 2024-05-01 12:08:49 +00:00
34fdd89d37 Removed blocking calls from directory listing function 2024-05-01 07:20:56 +02:00
b51ac3e171 Fix all compression algorithms dependent on Brotli 2024-04-29 20:08:33 +02:00
934f4dd475 Optimized HTTP compression functionality 2024-04-29 19:58:39 +02:00
ba3a247e49 Fix crashes related to the request ID generation 2024-04-29 19:20:17 +02:00
583c66ca3d Fix incompatibilites with Bun 2024-04-27 13:51:05 +02:00
7dfdc7209e Errors that occurred while adding SNI context to a server are now ignored. 2024-04-27 06:45:16 +02:00
9eb982dc92 Add an inspector condition to disabling stdout 2024-04-27 06:01:09 +02:00
3839f4d1df When stdout is not a terminal, disable it to improve performance of SVR.JS 2024-04-27 05:53:08 +02:00
3a4cefa67a Optimize portions from directory listing function 2024-04-24 13:03:53 +02:00
d789fea921 Move counter if blocks to another if block 2024-04-24 12:58:46 +02:00
4f5f96dfdb Disable OpenSSL EOL notification for Bun (Bun uses BoringSSL) 2024-04-24 12:52:32 +02:00
a986d3c523 Use os.availableParallelism if it is implemented 2024-04-21 19:39:30 +02:00
1ae35a1977 Replace (...).indexOf("/") != 0 with (...)[0] != "/" 2024-04-21 16:46:01 +02:00
70cb113715 Remove duplicate client socket check 2024-04-21 16:32:20 +02:00
50be3cb450 Fix server crashes with .dirimages 2024-04-13 11:13:57 +02:00
ebf996856e Merge branch 'main' of https://git.svrjs.org/svrjs 2024-04-13 11:08:56 +02:00
4820db0160 Fix .dirimages directory returning 500 error, if it is not present in the web root 2024-04-13 11:08:48 +02:00
9b3cb3100d Replaced deprecated "substr" function with "substring" 2024-04-10 09:15:23 +02:00
31c2a060ce GitHub test successful! 2024-04-08 18:32:25 +02:00
01e2ad023a Test GitHub mirror 2024-04-08 18:31:38 +02:00
Dorian Niemiec
6dc340e8bc
Update main.yml - change Git user name to "github" 2024-04-08 17:19:04 +02:00
Dorian Niemiec
c9cf370e0c
Update main.yml 2024-04-08 17:14:44 +02:00
Dorian Niemiec
4661cb9145
Create main.yml 2024-04-08 17:12:32 +02:00
8f67b72bc5 Make configJSON.enableCompression conditions consistent 2024-04-07 15:52:51 +02:00
98ed9d9242 Fix "enableCompression not found" error 2024-04-07 15:52:07 +02:00
9576dc6406 Fix problems with Brotli compression on Bun 2024-04-07 15:31:27 +02:00
8978515e49 Change the order of static file serving. 2024-04-07 09:27:02 +02:00
86234d4795 Optimize check for compressible data 2024-04-07 09:25:14 +02:00
80943bf695 Remove redundant fs.stat in static file serving function 2024-04-07 09:19:45 +02:00
e584cce286 Added CVE-2024-27982 notice 2024-04-03 18:56:01 +02:00
9bd64cc65a Disabled trailing slash redirection for proxy requests 2024-04-02 17:33:21 +02:00
ee568d252e Fix "Can't read property 1 of undefined" error. Also unify crash handlers. 2024-04-02 11:21:04 +02:00
1ef32bfe1d Change default configuration file 2024-04-02 11:01:13 +02:00
ccb90d07e5 Remove .kate-swp files 2024-04-02 11:00:47 +02:00
2cb4f8f491 Change default dontCompress regular expressions 2024-04-02 11:00:25 +02:00
6dd689e7d5 Update conditions for directory listing icons 2024-04-02 10:53:02 +02:00
0fc76179f3 Add .mov, .wma and .wmv files 2024-04-02 10:37:55 +02:00
b236064a9b Add default file formats not compressed list to SVR.JS itself. Also compressed audio/video file formats to one regular expression 2024-04-02 10:35:44 +02:00
b027443c47 Added more file formats to be excluded from compression 2024-04-02 10:30:26 +02:00
e3c1dcea0e Bun's crypto.scrypt doesn't block the event loop that much compared to crypto.pbkdf2 2024-04-01 21:48:19 +02:00
bac0e61487 Remove unneeded "listeningMessage.js" files 2024-03-31 19:30:13 +02:00
9eff118962 Change all of the internal calls to "callServerError" 2024-03-31 19:15:10 +02:00
51544f5732 Sort out the server error description list 2024-03-31 19:02:43 +02:00
36e57cfbef Collapse even more errno exit code 2024-03-31 18:58:19 +02:00
5638a45e6e Change code for Node.JS builds without crypto library 2024-03-31 18:55:27 +02:00
3b7271386c Make server listening error description list an object in the global scope 2024-03-31 18:51:39 +02:00
36b989f2ba Optimize server error handlers 2024-03-31 18:44:00 +02:00
428444a3a6 Fix bug with res.writeHead method 2024-03-29 10:58:50 +01:00
03a485c04a Fix bug with request domain names not showing in server logs 2024-03-19 17:12:28 +01:00
30367a1338 Fix the "SERVER MESSAGE" in SVR.JS log viewer and log highlighter 2024-03-17 21:39:21 +01:00
096121695c Update SVR.JS log viewer and log highlighter to reflect the changes in SVR.JS itself 2024-03-17 21:38:24 +01:00
be8cfe942e Make server message types bold 2024-03-17 21:32:39 +01:00
98de0a31dc Make "SVR.JS - a web server running on Node.JS" bold 2024-03-17 21:23:25 +01:00
155b808dbc Remove not applicable tests from test page 2024-03-17 15:20:44 +01:00
9a8f83bad9 Fix language error in the comment 2024-03-17 15:17:41 +01:00
cb81658318 Add "localhost" entry to the block list, when "block localhost" is typed into SVR.JS rather than "::ffff:localhost". 2024-03-17 15:13:07 +01:00
c85df7cd26 Make the improvement consistent with password verification function 2024-03-17 10:20:00 +01:00
32a92804fa Improve protection against user enumeration 2024-03-17 10:17:53 +01:00
184060fb79 Modified HTTP authentication functionality 2024-03-17 10:00:01 +01:00
7857e0e2fa Optimize non-standard code functionality 2024-03-17 09:30:26 +01:00
3493aa4d2d Remove <nocode> (non-standard) tags for bad (broken) directory listing entries 2024-03-17 00:59:53 +01:00
f1c74cb036 Optimized bad (broken) entry generation in directory listing 2024-03-17 00:57:47 +01:00
c44c796253 Optimized some request parameter logging 2024-03-17 00:54:47 +01:00
db621d9a88 Add more use of status code names in http.STATUS_CODES 2024-03-17 00:51:34 +01:00
4a09b14ff2 Change log message for client being in block list 2024-03-17 00:48:21 +01:00
ba21f655a4 Replaced client in the block list error message with generic 403 Forbidden error message 2024-03-17 00:46:32 +01:00
28244bf2c5 Replace some instances of "blacklist" (racist?) with "block list" 2024-03-17 00:39:21 +01:00
37f3d1d2af Changed CVE-2024-22019 warning text 2024-03-17 00:35:44 +01:00
e638c5dc1a Added CVE-2024-22019 Node.JS vulnerability warning. 2024-03-13 03:00:56 +01:00
1e165dcc58 Fix wwwredirect function 2024-03-09 16:32:01 +01:00
52e729f51d Optimize HTTP/1.x compatiblity res.writeHead function 2024-03-09 16:10:41 +01:00
0e44109776 Change error handler for missing HTTP/2 pseudoheaders 2024-03-09 16:08:46 +01:00
7b0038754e Optimize HTTP/1.x compatibility header setting 2024-03-09 16:00:19 +01:00
6c8873ce3f Fix comparison optimized in the previous commit 2024-03-09 15:57:56 +01:00
4a24b9d892 Be case insensitive in header name exclusion in shimmed HTTP/1.x res.writeHead method 2024-03-09 15:57:30 +01:00
70444f3b48 Optimize missing header check 2024-03-09 15:50:36 +01:00
9f8b0f4fe3 Remove try/catch block in HTTP/1.x compatibility shim; errors there are non-existent 2024-03-09 15:48:23 +01:00
8ac546ff67 Be case insensitive in header name exclusion in shimmed HTTP/1.x res.setHeader method 2024-03-09 15:45:31 +01:00
382d496934 Compressed default directory listing icons 2024-03-03 20:59:20 +01:00
48f638ec01 Changed license page: added maximum width to list of packages used by SVR.JS 2024-03-03 16:14:40 +01:00
af4f8b2105 Change SVR.JS logo CSS properties on the default page 2024-03-03 16:08:28 +01:00
c05948467f Make the default page fit on very small screens 2024-03-03 16:05:56 +01:00
1a9f31c5d0 Show list bullets on browsers not supporting "display: inline-block" on the default page. 2024-03-03 15:58:56 +01:00
6238f5eb9e Changed the default configuration file 2024-03-03 15:56:19 +01:00
c9162f9e7b Expanded color values on Nightly version warning banner 2024-03-03 15:54:29 +01:00
8073f51730 Changed design of the default page 2024-03-03 15:53:04 +01:00
897c080884 Changed default directory listing icons 2024-03-03 15:28:35 +01:00
9017b732cc Clean up the code. 2024-03-03 02:05:14 +01:00
c20aa3d7bc Completely rewrite HTTP to HTTPS redirect functionality 2024-03-03 00:01:17 +01:00
067d177321 Optimized some regular expressions 2024-03-02 22:57:27 +01:00
3a966d342a Added option to allow URLs with double slashes 2024-03-02 22:54:03 +01:00
47803c217b Fix URL rewriter always remove double slashes 2024-03-02 22:45:27 +01:00
cbbe4c9bc5 Fix errors with web root postfix adding functionality 2024-03-02 22:41:26 +01:00
0f0c1b22ab Prepare web root postfix adding functionality for double slash URL support 2024-03-02 22:21:49 +01:00
d633707ea5 Prevent redirect loops with fallback replacement 2024-03-02 22:11:50 +01:00
2f232614a2 Fix URL rewriting on URLs with double slashes 2024-03-02 22:02:24 +01:00
28d633884e Prepare for double slash URL support 2024-03-02 21:54:07 +01:00
bd5ab63954 Change lookahead token order in two URL sanitation regular expressions 2024-02-28 21:45:47 +01:00
ae630a1625 URL sanitizer function now uses less regular expression replacements. 2024-02-28 21:43:43 +01:00
c3aba19ca3 Updated "tar" and "graceful-fs" libraries 2024-02-22 02:50:46 +01:00
38350597e5 Change SVR.JS logo file to one from https://svrjs.org/logo.png 2024-02-11 21:31:44 +01:00
6f362f15ac Set enableIPSpoofing in config.json to false by default 2024-02-11 21:28:59 +01:00
b829414f4c Fixed bug with URLs beginning with multiple slashes being rewritten incorrectly. 2024-02-11 21:26:26 +01:00
5339f4c244 Change default configuration file and test page. 2024-02-07 00:42:34 +01:00
2589eff15f Added new SVR.JS mod and server-side JavaScript variable: authUser. 2024-02-07 00:35:00 +01:00
94320d348f Remove easter egg mod 2024-02-02 19:55:10 +01:00
9f15a08378 Add some code comments 2024-02-02 19:49:30 +01:00
d85dedea65 Clean up the code. 2024-02-02 19:32:40 +01:00
88e923ffbc Fixed SVR.JS crashes with X-SVR-JS-From-Main-Thread header and unspecified client request IPs 2024-02-02 19:23:45 +01:00
4d69f6f1a7 Add IP-based virtual hosts alongside hostname-based virtual hosts 2024-02-02 19:08:49 +01:00
ea228114e1 Head and foot inclusion is now returning 500 error in case of server error instead of server crash. 2024-01-24 19:48:50 +00:00
e172c2c005 Fix web root postfix prefix support 2024-01-24 19:06:00 +00:00
e29d1aa3aa Fix syntax error from previous commit. 2024-01-24 18:53:29 +00:00
5fdbc898d0 Add support for web root postfix prefixes. 2024-01-24 18:52:05 +00:00
6abe280ee8 Add support for web root postfixes (for every host) 2024-01-23 07:00:23 +01:00
6a9afcbc26 Add support for useClientCertificate, rejectUnauthorizedClientCertificates, cipherSuite, ecdhCurve, tlsMinVersion, tlsMaxVersion, signatureAlgorithms and http2Settings config.json properties. 2024-01-22 23:21:01 +01:00
1a2019664a Fixed error handling for invalid URL rewrite regexes. Also fixed bug with HTTP proxy not working. 2024-01-18 01:12:09 +01:00
60a84d879d Clean up the code (remove trailing spaces) 2024-01-14 19:01:49 +01:00
db6c4faeaf Mitigate log file injection vulnerability at mod file names. 2024-01-14 19:00:27 +01:00
e1e9338806 SVR.JS no longer crashes, when access to a log file is denied. 2024-01-14 09:00:08 +01:00
e11dd8d5b5 Mitigated log file injection for HTTP authentication 2024-01-14 08:41:11 +01:00
55dfa0ad1e Fixed typo that caused 500 error with 308 code redirects 2024-01-13 10:25:42 +01:00
9569c7b7fd Added support for 307 and 308 redirects (both in config.json and in redirect() SVR.JS API method) 2024-01-13 08:36:00 +01:00
fef016dd1c Remove svrmodpack from node_modules 2024-01-13 08:27:41 +01:00
03556813ec Reformatted the source code 2024-01-13 08:25:38 +01:00
1123f40961 Cleaned up the code 2024-01-13 08:09:32 +01:00
4179e4020c Dropped support for svrmodpack; SVR.JS LTS versions will still have svrmodpack support. 2024-01-13 08:01:05 +01:00
7e73cb68d3 Added support for skipping URL rewriting, when the URL refers to a file or a directory. 2024-01-13 07:53:16 +01:00
d942342106 Changed rewriteURL method to use callbacks. 2024-01-13 07:34:28 +01:00
506df5ada7 Changed "SVR.JS authors" in custom feet to "SVR.JS". 2023-12-31 00:41:44 +01:00
7a6661b895 Fix searchHostname function 2023-12-30 23:43:07 +01:00
c46baf94b0 Replace "SVR.JS authors" with "SVR.JS" 2023-12-30 23:39:31 +01:00
b0ed92d8ac Removed all remnants of "DorianTech" in SVR.JS 2023-12-24 19:17:34 +01:00
7be1c2a73b Fixed host name rewriting 2023-12-16 08:59:49 +01:00
949e799d45 Improved SNI and host header processing 2023-12-15 23:28:06 +01:00
e68118ecbc Improve on new SNI-related changes 2023-12-15 00:50:33 +01:00
aac6323401 Add Host header processing 2023-12-15 00:15:54 +01:00
63f8e98add SVR.JS now refuses to start with misconfigured SNI in order to prevent ReDoS vulnerabilities. 2023-12-15 00:05:22 +01:00
179ebf6a7f Changed secure context regex generation 2023-12-14 23:45:50 +01:00
355d20a2c1 Optimized some anti-XSS measures 2023-12-12 23:22:06 +01:00
2faf1e9c61 Mitigated even more XSS vulnerabilities. 2023-12-12 23:19:29 +01:00
8bad3f918c Fixed multiple XSS vulnerabilities 2023-12-12 23:09:39 +01:00
5950d326fe Clean up res.writeHead wraooer code 2023-12-12 22:37:23 +01:00
5902dd52fc Added client errors, server errors, and malformed HTTP request counts to SVR.JS status page. 2023-12-12 22:29:27 +01:00
2fb4c52777 Make status page code more readable. 2023-12-12 22:19:51 +01:00
953c95f485 Fixes bug in the sizify function 2023-12-07 09:56:09 +01:00
ab69abf2da Fixed bug with URL rewriting and trailing slash redirection 2023-12-03 16:18:21 +01:00
33d89f01d3 Changed licenses page 2023-12-03 14:21:09 +01:00
5f586cee0a Changed tests page 2023-12-03 14:18:44 +01:00
2cab4349f9 Minor code style corrections 2023-12-03 14:04:38 +01:00
7229661c8e Replace all instances of "ex" with "err" 2023-12-03 14:00:52 +01:00
ebe310eca6 Clean up SVR.JS code 2023-12-03 13:58:35 +01:00
caf2ad685d Fix environment variable support (after testing) 2023-12-03 13:55:56 +01:00
d02c9754c9 Invalid compression exclusion list regexes no longer crash SVR.JS 2023-12-03 13:09:56 +01:00
17def48271 Changed invalid regex error message 2023-12-03 13:07:28 +01:00
0ed74bc55d Change base 1000 size prefixes to base 1024. 2023-12-03 12:51:05 +01:00
ae1738166f Add new config.json option - environmentVariables. 2023-12-03 12:11:15 +01:00
1f42691cbc Correct language errors 2023-12-03 12:05:14 +01:00
024d6cc2d3 SVR.JS now saves configuration files with trailing newlines. 2023-12-03 12:02:49 +01:00
4c9cd87a94 Change default configuration 2023-12-03 12:01:59 +01:00
5321f2c6a7 Added trailing slash redirect support 2023-12-03 11:55:19 +01:00
1f603ec262 Fixed language error in defualt index page. 2023-11-12 20:03:50 +01:00
82cfe10669 Update logo in SVR.JS log viewer. 2023-11-12 20:00:19 +01:00
10b7da09ae Corrected language errors in console error messages. 2023-11-12 19:52:59 +01:00
13603adf1b Fix even more language errors in HTTP error message descriptions. 2023-11-12 19:47:32 +01:00
fad9dc61ae Fix multiple language errors in HTTP error message descriptions. 2023-11-12 18:59:24 +01:00
b38e1cea5f Fixed crashes due of destroyed HTTP/2 stream (Node.JS bug: https://github.com/nodejs/node/issues/24470) 2023-11-12 18:41:06 +01:00
ae45c2e132 SVR.JS now sends configuration file saving request to one random good worker instead of all workers to prevent configuration file corruption. 2023-11-12 18:33:29 +01:00
fccc0ef7ca Fixed bug with non-standard code regex replacements 2023-09-17 23:32:42 +02:00
a2ecbe4c5a Optimize mod loader 2023-09-12 23:19:14 +02:00
84b7cac684 Fix bug with mods executing in wrong order (bug was related with access control vulnerability fix; bug was not present in LTS versions) 2023-09-12 23:15:55 +02:00
80dbafe3ee Clean up remnants after removal of primitiveanalytics.tar.gz mod. 2023-09-12 21:21:11 +02:00
c8c069aceb Rename properDirectoryListingServe function to properDirectoryListingAndStaticFileServe. 2023-09-12 19:50:39 +02:00
75e987dcf4 Removed undocumented and non-working code. 2023-09-12 19:34:34 +02:00
e84bb426a7 Replace sizify function with new one. 2023-09-12 19:21:13 +02:00
5a567d09d1 Drop dependency on "pretty-bytes" module 2023-09-12 18:27:15 +02:00
e048156e18 Remove "invoke500.svr" and "crash.svr" (only activated in nightly versions, not in stable or LTS) 2023-09-12 18:11:11 +02:00
8050fc766e Partially revert commit 193cede707 2023-09-11 23:21:14 +02:00
8fef063375 Fixed one more error in default server-side JavaScript 2023-09-11 23:08:53 +02:00
193cede707 Optimize responseEnd method 2023-09-11 23:08:02 +02:00
11bc6a32c9 Remove "fd" variable. 2023-09-11 23:01:46 +02:00
cbec4c4e6c Modify built-in server-side JavaScript 2023-09-11 22:56:56 +02:00
1132ed539a Remove unneccesary whitespaces 2023-09-11 21:56:08 +02:00
f4641cd1bb Removed unused SVR.JS code 2023-09-11 21:51:03 +02:00
079ce3d974 Reposition some if conditions 2023-09-11 21:50:42 +02:00
68e7fa9ae6 Globalize HTTP error messages object 2023-09-11 11:06:03 +02:00
91ab1f4a97 Minor changes to status codes 2023-09-11 10:36:10 +02:00
38bacc1781 Fix main page 2023-09-10 19:41:23 +02:00
e828bb9173 Add warning about worker count limited to one when using Bun 1.0 and newer with shimmed (not native) clustering module. 2023-09-10 19:30:29 +02:00
7973dafa60 Remove bug section from index page 2023-09-10 19:04:50 +02:00
24783fc1f9 Disable bug workaround for Bun 1.0 and newer (it's not needed anymore for these Bun versions) 2023-09-10 19:03:28 +02:00
b39471e8b8 Improve Bun shim 2023-09-10 18:58:05 +02:00
2ec6b564f5 Improve web root error handling 2023-09-10 18:37:09 +02:00
15ca36cf16 Fixed security vulnerability with information leakage from "temp" directory 2023-09-10 10:50:18 +02:00
d0064ee083 Log certificate loading errors 2023-09-10 10:35:07 +02:00
c7c381d8c9 Fix log files only partially saving on failed master startup 2023-09-10 10:14:24 +02:00
f475aa8651 Remove one obsolete process.cwd() == __dirname check 2023-09-09 00:53:24 +02:00
53560a7bcd Mitigiate source-code leakage through hidden files in temp folder. Also change default enableRemoteLogBrowsing to false. 2023-09-09 00:36:24 +02:00
6066f77fae Fix svrmodpack deprecation warning 2023-09-08 20:17:38 +02:00
1e2d61ff64 Improved Bun workaround 2023-09-08 20:08:46 +02:00
3edbc80e7d Added TypeError workaround for Bun 1.0.0. Bun 1.0.0 now supports IPC 2023-09-08 20:00:02 +02:00
bc6268e2c0 Change no HTTP/2 warning 2023-09-08 19:39:18 +02:00
b5ac862f5e Add "svrmodpack" deprecation warning 2023-09-08 19:26:40 +02:00
be4819e3ea Remove unmaintained primitive analytics mod 2023-09-08 19:15:47 +02:00
7f2da5b12a Remove unmaintained and undocumented hexstrbase64 library 2023-09-08 19:12:42 +02:00
2d733b70bf Fix access control bypass vulnerability for non-proxy SVR.JS mods 2023-09-07 18:00:58 +02:00
2c93e0fc24 Complete out previous fix 2023-09-06 20:22:51 +02:00
08816fe4f3 Mitigated security vulnerability: SVR.JS mods and server-side JavaScript using req.url could be vulnerable to path traversal. 2023-09-06 19:22:03 +02:00
dc23125ce4 Fix an error in previous commit 2023-09-05 00:15:00 +02:00
2ab7fab9cf Added new property in config.json - exposeModsInErrorPages 2023-09-05 00:05:20 +02:00
Dorian Niemiec
5ba3d8f2b3 Moved invalid X-Forwader-For header handler 2023-09-03 22:40:10 +02:00
Dorian Niemiec
61b0d6ad9c Added missing semicolon 2023-09-03 22:31:07 +02:00
Dorian Niemiec
b1ab6e3e4a Added validation of X-Forwarded-For header 2023-09-03 14:40:41 +02:00
Dorian Niemiec
d8cf7913be Change listening notice 2023-09-03 11:10:01 +02:00
Dorian Niemiec
bd7098c2c6 Cleaned up SVR.JS code even more... 2023-09-03 11:08:16 +02:00
Dorian Niemiec
8dd707c44d Add notice about user being logged in. 2023-09-03 10:27:30 +02:00
Dorian Niemiec
9946c301e4 Cleaned up SVR.JS code 2023-09-03 10:18:52 +02:00
a663b4f142 Improved error handling of SVR.JS configuration, mods and server-side JavaScript. 2023-09-02 20:27:27 +02:00
817db0fff9 Replaced HTTPS redirect handler 2023-09-02 19:56:45 +02:00
b21b8dc84c Moved and fixed bug with "wwwredirect" 2023-09-02 19:35:01 +02:00
fdac578678 Dropped support for HTTP to HTTPS redirect bypass headers 2023-09-02 19:12:46 +02:00
1637e87550 Dropped support for unused SVR.JS-specific X-SVR-JS-Client header (use X-Forwarded-For header instead) 2023-09-02 18:33:09 +02:00
9b27bacf25 Add support for listening to specific IP address. 2023-09-02 18:15:00 +02:00
08692a2ff5 Added new config.json property - useWebRootServerSideScript 2023-09-02 12:57:19 +02:00
1578a82069 Change default SVR.JS configuration. 2023-09-02 09:19:14 +02:00
a7185d6c94 Disable server-side script exposure by default. 2023-09-02 09:01:25 +02:00
03b54f94d4 Fix callServerError 2023-09-01 11:04:04 +02:00
bf3b002190 Optimize filterHeaders and add checkHostname and checkHref 2023-09-01 01:13:15 +02:00
bbb8a6f899 Replace "request" with "req" and "response" with "res" 2023-08-31 23:03:02 +02:00
4a138f73d8 Add virtual host support 2023-08-31 22:47:07 +02:00
e490f8341b Fix modFunction 2023-08-29 15:44:01 +02:00
71d1970571 Cleaned up SVR.JS code 2023-08-29 15:03:13 +02:00
1ebf19d768 Fixed non-working blacklist 2023-08-29 14:56:39 +02:00
10f9e1b5f2 Add reverse DNS lookup support 2023-08-28 03:44:04 +02:00
94a7b319f6 Fixed server crashes while one of two ports are in use 2023-08-25 00:26:51 +02:00
2d266bf1b3 Map ENAMETOOLONG to 414 code 2023-08-21 19:38:38 +02:00
54ba71212b Pull from SVR.JS 3.7.1 2023-08-21 19:32:31 +02:00
e6c1194086 Fixed checkEXT again 2023-08-19 23:18:52 +02:00
bfcc88a4dd Fixed checkEXT function 2023-08-19 23:16:27 +02:00
d31d47bbcd Rewritten some of for loops to use forEach instead. 2023-08-19 22:38:58 +02:00
e7e232f6e7 Restored easter eggs to easteregg.tar.gz mod, which can be deleted. Also change unused worker kill interval. 2023-08-19 21:19:18 +02:00
fba0012690 Removed some easter eggs, to prevent SVR.JS version fingerprinting... 2023-08-19 21:03:05 +02:00
b96d39cb3e Disabled open proxy in default server-side JavaScript 2023-08-18 23:55:36 +02:00
aedbd134f8 Add option to rewrite "dirty" URLs 2023-08-18 23:29:18 +02:00
bd475a2e8e Fixed redirect loops related to URL sanitizer 2023-08-18 21:54:58 +02:00
47a793b958 Added scrypt support for HTTP authentication 2023-08-18 21:35:09 +02:00
d93511e97b Enable use of PBKDF2-hashed passwords 2023-08-15 19:05:44 +02:00
f8cc7e45cd Optimize credential match checking 2023-08-15 14:04:29 +02:00
cbbf8ab79b EMFILE errors now correspond to 503 Service Unavailable error code. 2023-08-13 00:43:21 +02:00
028606fb15 Fix redirect loop with "[" and "]". 2023-08-12 17:40:42 +02:00
86d424f906 Add config.json option to disable termination of unused workers 2023-08-12 13:37:06 +02:00
e4332e858c Improved error handling for Bun even more. 2023-08-12 13:23:59 +02:00
f0193b5933 Improve server error handling for Bun. 2023-08-12 12:47:48 +02:00
61dead9b4a Improved extension checking function and corrected 503 error description 2023-08-12 12:35:46 +02:00
f37a565ca1 Changed descriptions of 501 and 503 errors. 2023-08-12 12:07:33 +02:00
Dorian Niemiec
986c883327 Improve Bun fake IPC connections error handling. 2023-08-10 04:20:30 +02:00
Dorian Niemiec
7820c5aade Fix Bun cluster shim and mitigate Bun segmentation faults 2023-08-10 04:01:50 +02:00
Dorian Niemiec
8ca945cdbd Fixed master spawning other masters while SVR.JS is run in Bun 0.7.x. 2023-08-10 03:16:52 +02:00
Dorian Niemiec
7cc4dbf4d2 Fix cluster NotImplementedError when running SVR.JS on newer versions of Bun. 2023-08-10 02:03:23 +02:00
Dorian Niemiec
3d4acae311 Make SVR.JS gracefully exit on "stop" command. 2023-08-10 01:14:10 +02:00
Dorian Niemiec
08cc0ac042 Improved minimum thread count calculation algorithm even further. Also disabled x-svr-js-from-main-thread requests from non-localhost clients. 2023-08-09 23:03:16 +02:00
Dorian Niemiec
889207e6a2 Disabled checking for hung up server processes, while SVR.JS is not listening yet. Also improved minimum thread count calculation algorithm. 2023-08-09 22:37:53 +02:00
Dorian Niemiec
6515a54471 Disabled killing workers, when server is closed. 2023-08-09 21:58:21 +02:00
Dorian Niemiec
68a42ccde8 Fixed bug with Can't execute command "KILLREQ". 2023-08-09 21:23:50 +02:00
Dorian Niemiec
e6a25d931c Add termination of unused workers. 2023-08-09 21:09:23 +02:00
Dorian Niemiec
1138b6bdf6 Replace "isMaster" with "isPrimary", and shim "isPrimary" when it's not available. 2023-08-09 18:01:36 +02:00
Dorian Niemiec
aa630cbd0d Changed all references for stable version to git master branch 2023-08-06 04:07:04 +02:00
18 changed files with 1321 additions and 1356 deletions

View file

@ -8,10 +8,10 @@
It's free as in freedom, scalable, secure, and configurable. It's free as in freedom, scalable, secure, and configurable.
</p> </p>
<p align="center"> <p align="center">
<a href="https://svrjs.org/docs/tentative" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Documentation-green"></a> <a href="https://svrjs.org/docs" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Documentation-green"></a>
<a href="https://svrjs.org" target="_blank"><img alt="Website" src="https://img.shields.io/website?url=https%3A%2F%2Fsvrjs.org"></a> <a href="https://svrjs.org" target="_blank"><img alt="Website" src="https://img.shields.io/website?url=https%3A%2F%2Fsvrjs.org"></a>
<a href="https://hub.docker.com/r/svrjs/svrjs" target="_blank"><img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/svrjs/svrjs"></a> <a href="https://hub.docker.com/r/svrjs/svrjs" target="_blank"><img alt="Docker Pulls" src="https://img.shields.io/docker/pulls/svrjs/svrjs"></a>
<a href="https://github.com/svr-js/svrjs/tree/next" target="_blank"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/svr-js/svrjs"></a> <a href="https://github.com/svr-js/svrjs" target="_blank"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/svr-js/svrjs"></a>
<a href="https://x.com/SVR_JS" target="_blank"><img alt="X (formerly Twitter) Follow" src="https://img.shields.io/twitter/follow/SVR_JS"></a> <a href="https://x.com/SVR_JS" target="_blank"><img alt="X (formerly Twitter) Follow" src="https://img.shields.io/twitter/follow/SVR_JS"></a>
<a href="https://mastodon.social/@svrjs" target="_blank"><img alt="Mastodon Follow" src="https://img.shields.io/mastodon/follow/111643338718098121"></a> <a href="https://mastodon.social/@svrjs" target="_blank"><img alt="Mastodon Follow" src="https://img.shields.io/mastodon/follow/111643338718098121"></a>
</p> </p>
@ -87,7 +87,7 @@ After running the command, you will get bundled SVR.JS script, around with built
To install SVR.JS you just built from the source code, you can install it via SVR.JS installer for GNU/Linux or manually. To install SVR.JS you just built from the source code, you can install it via SVR.JS installer for GNU/Linux or manually.
If you want to install SVR.JS manually, you can read the [server documentation](https://svrjs.org/docs/tentative). If you want to install SVR.JS manually, you can read the [server documentation](https://svrjs.org/docs).
If you want to install via SVR.JS installer for GNU/Linux, run this command: If you want to install via SVR.JS installer for GNU/Linux, run this command:
```bash ```bash
@ -102,7 +102,7 @@ After installation, SVR.JS should be listening at http://localhost.
## SVR.JS documentation ## SVR.JS documentation
You can read the [SVR.JS documentation](https://svrjs.org/docs/tentative) to get information on how to use SVR.JS. You can read the [SVR.JS documentation](https://svrjs.org/docs) to get information on how to use SVR.JS.
## npm scripts ## npm scripts

View file

@ -59,5 +59,6 @@
"disableTrailingSlashRedirects": false, "disableTrailingSlashRedirects": false,
"environmentVariables": {}, "environmentVariables": {},
"allowDoubleSlashes": false, "allowDoubleSlashes": false,
"optOutOfStatisticsServer": false "optOutOfStatisticsServer": false,
"disableConfigurationSaving": false
} }

View file

@ -4,248 +4,362 @@ const fs = require("fs");
const zlib = require("zlib"); const zlib = require("zlib");
const ejs = require("ejs"); const ejs = require("ejs");
const archiver = require("archiver"); const archiver = require("archiver");
const dependencies = const chokidar = require("chokidar");
JSON.parse(fs.readFileSync(__dirname + "/package.json")).dependencies || {};
const requiredDependencyList = Object.keys(dependencies);
let dependencyList = Object.keys(dependencies);
const svrjsInfo = JSON.parse(fs.readFileSync(__dirname + "/svrjs.json")); const svrjsInfo = JSON.parse(fs.readFileSync(__dirname + "/svrjs.json"));
const { name, version, documentationURL, changes } = svrjsInfo; const { version } = svrjsInfo;
const isDev = process.env.NODE_ENV == "development";
// Function to find and add all dependencies into the dependencyList array. // Create the dist directory if it doesn't exist
function findAllDependencies(curList) { if (!fs.existsSync(__dirname + "/dist")) fs.mkdirSync(__dirname + "/dist");
// If no curList parameter is specified, use dependencyList. if (!fs.existsSync(__dirname + "/dist/log"))
if (!curList) curList = dependencyList; fs.mkdirSync(__dirname + "/dist/log");
curList.forEach((dependency) => { if (!fs.existsSync(__dirname + "/dist/mods"))
const newDeplist = Object.keys( fs.mkdirSync(__dirname + "/dist/mods");
JSON.parse( if (!fs.existsSync(__dirname + "/dist/temp"))
fs fs.mkdirSync(__dirname + "/dist/temp");
.readFileSync(
__dirname +
"/node_modules/" +
dependency.replace(/\/\.\./g, "") +
"/package.json"
)
.toString()
).dependencies || {}
);
let noDupNewDepList = [];
newDeplist.forEach((dep) => {
// Ignore duplicates
if (dependencyList.indexOf(dep) == -1) {
noDupNewDepList.push(dep);
dependencyList.push(dep);
}
});
// Call findAllDependencies for the dependency list.
findAllDependencies(noDupNewDepList);
});
}
// Get list of all dependencies // Create the out directory if it doesn't exist and if not building for development
findAllDependencies(); if (!isDev && !fs.existsSync(__dirname + "/out")) fs.mkdirSync(__dirname + "/out");
dependencyList = dependencyList.sort();
// Create and populate an object, where whenever the dependencies are required are listed. function generateAssets() {
let dependenciesAreRequired = {}; // Variables from "svrjs.json" file
dependencyList.forEach((dependency) => { const svrjsInfo = JSON.parse(fs.readFileSync(__dirname + "/svrjs.json"));
dependenciesAreRequired[dependency] = false; const { name, version, documentationURL, changes } = svrjsInfo;
});
requiredDependencyList.forEach((dependency) => {
dependenciesAreRequired[dependency] = true;
});
// Create the template functions using EJS // Dependency-related variables
const layoutTemplate = ejs.compile( const dependencies =
fs.readFileSync(__dirname + "/templates/layout.ejs").toString() JSON.parse(fs.readFileSync(__dirname + "/package.json")).dependencies || {};
); const requiredDependencyList = Object.keys(dependencies);
const testsTemplate = ejs.compile( let dependencyList = Object.keys(dependencies);
fs.readFileSync(__dirname + "/templates/tests.ejs").toString()
);
const indexTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/index.ejs").toString()
);
const licensesTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/licenses.ejs").toString()
);
const licenseElementTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/licenseElement.ejs").toString()
);
let licenseElements = ""; // Function to find and add all dependencies into the dependencyList array.
const findAllDependencies = (curList) => {
// Generate the licenses list in HTML // If no curList parameter is specified, use dependencyList.
dependencyList.forEach((dependency) => { if (!curList) curList = dependencyList;
const packageJSON = JSON.parse( curList.forEach((dependency) => {
fs const newDeplist = Object.keys(
.readFileSync( JSON.parse(
__dirname + fs
"/node_modules/" + .readFileSync(
dependency.replace(/\/\.\./g, "") + __dirname +
"/package.json" "/node_modules/" +
) dependency.replace(/\/\.\./g, "") +
.toString() "/package.json"
); )
licenseElements += licenseElementTemplate({ .toString()
moduleName: packageJSON.name, ).dependencies || {}
name: name, );
license: packageJSON.license, let noDupNewDepList = [];
description: packageJSON.description || "No description", newDeplist.forEach((dep) => {
author: packageJSON.author ? packageJSON.author.name : packageJSON.author, // Ignore duplicates
required: dependenciesAreRequired[dependency] if (dependencyList.indexOf(dep) == -1) {
}); noDupNewDepList.push(dep);
}); dependencyList.push(dep);
// Generate pages
const licensesPage = layoutTemplate({
title: name + " " + version + " Licenses",
content: licensesTemplate({
name: name,
version: version,
licenses: licenseElements
})
});
const testsPage = layoutTemplate({
title: name + " " + version + " Tests",
content: testsTemplate({
name: name,
version: version
})
});
const indexPage = layoutTemplate({
title: name + " " + version,
content: indexTemplate({
name: name,
version: version,
documentationURL: documentationURL,
changes: changes
})
});
// Remove the generated assets directory if exists, and create a new one.
if (fs.existsSync(__dirname + "/generatedAssets")) {
if (fs.rmSync) fs.rmSync(__dirname + "/generatedAssets", { recursive: true });
else fs.rmdirSync(__dirname + "/generatedAssets", { recursive: true });
}
fs.mkdirSync(__dirname + "/generatedAssets");
// Remove the dist directory if exists, and create a new one.
if (fs.existsSync(__dirname + "/dist")) {
if (fs.rmSync) fs.rmSync(__dirname + "/dist", { recursive: true });
else fs.rmdirSync(__dirname + "/dist", { recursive: true });
}
fs.mkdirSync(__dirname + "/dist");
fs.mkdirSync(__dirname + "/dist/log");
fs.mkdirSync(__dirname + "/dist/mods");
fs.mkdirSync(__dirname + "/dist/temp");
// Remove the out directory if exists, and create a new one.
if (fs.existsSync(__dirname + "/out")) {
if (fs.rmSync) fs.rmSync(__dirname + "/out", { recursive: true });
else fs.rmdirSync(__dirname + "/out", { recursive: true });
}
fs.mkdirSync(__dirname + "/out");
// Create a licenses directory
fs.mkdirSync(__dirname + "/generatedAssets/licenses");
// Write to HTML files
fs.writeFileSync(__dirname + "/generatedAssets/index.html", indexPage);
fs.writeFileSync(__dirname + "/generatedAssets/tests.html", testsPage);
fs.writeFileSync(
__dirname + "/generatedAssets/licenses/index.html",
licensesPage
);
// Bundle the source and copy the assets using esbuild and esbuild-plugin-copy
esbuild
.build({
entryPoints: ["src/index.js"],
bundle: true,
outfile: "dist/svr.js",
platform: "node",
target: "es2017",
plugins: [
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
from: ["./assets/**/*"],
to: ["./dist"]
},
globbyOptions: {
dot: true
} }
}),
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
from: ["./generatedAssets/**/*"],
to: ["./dist"]
}
})
]
})
.then(() => {
const utilFilesAndDirectories = fs.existsSync(
__dirname + "/src/extraScripts"
)
? fs.readdirSync(__dirname + "/src/extraScripts")
: [];
const utilFiles = [];
utilFilesAndDirectories.forEach((entry) => {
if (fs.statSync(__dirname + "/src/extraScripts/" + entry).isFile())
utilFiles.push(entry);
});
// Transpile utilities using esbuild
esbuild
.build({
entryPoints: utilFiles.map(
(filename) => "src/extraScripts/" + filename
),
bundle: true,
outdir: "dist",
platform: "node",
target: "es2017"
})
.then(() => {
const archiveName =
"svr.js." +
version.toLowerCase().replace(/[^0-9a-z]+/g, ".") +
".zip";
const output = fs.createWriteStream(__dirname + "/out/" + archiveName);
const archive = archiver("zip", {
zlib: { level: 9 }
});
archive.pipe(output);
// Add everything in the "dist" directory except for "svr.js" and "svr.compressed"
archive.glob("**/*", {
cwd: __dirname + "/dist",
ignore: ["svr.js", "svr.compressed"],
dot: true
});
// Create a stream for the "svr.compressed" file
const compressedSVRJSFileStream = fs
.createReadStream(__dirname + "/dist/svr.js")
.pipe(
zlib.createGzip({
level: 9
})
);
archive.append(compressedSVRJSFileStream, { name: "svr.compressed" });
archive.append(
'const zlib = require("zlib");\nconst fs = require("fs");\nconsole.log("Deleting SVR.JS stub...");\nfs.unlinkSync("svr.js");\nconsole.log("Decompressing SVR.JS...");\nconst script = zlib.gunzipSync(fs.readFileSync("svr.compressed"));\nfs.unlinkSync("svr.compressed");\nfs.writeFileSync("svr.js",script);\nconsole.log("Restart SVR.JS to get server interface.");',
{ name: "svr.js" }
);
archive.finalize();
})
.catch((err) => {
throw err;
}); });
}) // Call findAllDependencies for the dependency list.
.catch((err) => { findAllDependencies(noDupNewDepList);
throw err; });
};
// Get list of all dependencies
findAllDependencies();
dependencyList = dependencyList.sort();
// Create and populate an object, where whenever the dependencies are required are listed.
let dependenciesAreRequired = {};
dependencyList.forEach((dependency) => {
dependenciesAreRequired[dependency] = false;
}); });
requiredDependencyList.forEach((dependency) => {
dependenciesAreRequired[dependency] = true;
});
// Create the template functions using EJS
const layoutTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/layout.ejs").toString()
);
const testsTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/tests.ejs").toString()
);
const indexTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/index.ejs").toString()
);
const licensesTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/licenses.ejs").toString()
);
const licenseElementTemplate = ejs.compile(
fs.readFileSync(__dirname + "/templates/licenseElement.ejs").toString()
);
let licenseElements = "";
// Generate the licenses list in HTML
dependencyList.forEach((dependency) => {
const packageJSON = JSON.parse(
fs
.readFileSync(
__dirname +
"/node_modules/" +
dependency.replace(/\/\.\./g, "") +
"/package.json"
)
.toString()
);
licenseElements += licenseElementTemplate({
moduleName: packageJSON.name,
name: name,
license: packageJSON.license,
description: packageJSON.description || "No description",
author: packageJSON.author ? packageJSON.author.name : packageJSON.author,
required: dependenciesAreRequired[dependency]
});
});
// Generate pages
const licensesPage = layoutTemplate({
title: name + " " + version + " Licenses",
content: licensesTemplate({
name: name,
version: version,
licenses: licenseElements
})
});
const testsPage = layoutTemplate({
title: name + " " + version + " Tests",
content: testsTemplate({
name: name,
version: version
})
});
const indexPage = layoutTemplate({
title: name + " " + version,
content: indexTemplate({
name: name,
version: version,
documentationURL: documentationURL,
changes: changes
})
});
// Create the generated assets directory if it doesn't exist
if (!fs.existsSync(__dirname + "/generatedAssets"))
fs.mkdirSync(__dirname + "/generatedAssets");
// Create a licenses directory
if (!fs.existsSync(__dirname + "/generatedAssets/licenses"))
fs.mkdirSync(__dirname + "/generatedAssets/licenses");
// Write to HTML files
fs.writeFileSync(__dirname + "/generatedAssets/index.html", indexPage);
fs.writeFileSync(__dirname + "/generatedAssets/tests.html", testsPage);
fs.writeFileSync(
__dirname + "/generatedAssets/licenses/index.html",
licensesPage
);
}
if (!isDev) {
// Generate assets
generateAssets();
} else {
// Generate assets with watching
const watcher = chokidar.watch([
__dirname + "/templates",
__dirname + "/package.json",
__dirname + "/svrjs.json"
]);
watcher.on("change", () => {
try {
generateAssets();
} catch (err) {
console.error("There is a problem when regenerating assets!");
console.error("Stack:");
console.error(err.stack);
}
}).on("ready", () => {
try {
generateAssets();
} catch (err) {
console.error("There is a problem when regenerating assets!");
console.error("Stack:");
console.error(err.stack);
}
});
}
if (!isDev) {
// Bundle the source and copy the assets using esbuild and esbuild-plugin-copy
esbuild
.build({
entryPoints: ["src/index.js"],
bundle: true,
outfile: "dist/svr.js",
platform: "node",
target: "es2017",
plugins: [
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
from: ["./assets/**/*"],
to: ["./dist"]
},
globbyOptions: {
dot: true
}
}),
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
from: ["./generatedAssets/**/*"],
to: ["./dist"]
}
})
]
})
.then(() => {
const utilFilesAndDirectories = fs.existsSync(
__dirname + "/src/extraScripts"
)
? fs.readdirSync(__dirname + "/src/extraScripts")
: [];
const utilFiles = [];
utilFilesAndDirectories.forEach((entry) => {
if (fs.statSync(__dirname + "/src/extraScripts/" + entry).isFile())
utilFiles.push(entry);
});
// Transpile utilities using esbuild
esbuild
.build({
entryPoints: utilFiles.map(
(filename) => "src/extraScripts/" + filename
),
bundle: true,
outdir: "dist",
platform: "node",
target: "es2017"
})
.then(() => {
const archiveName =
"svr.js." +
version.toLowerCase().replace(/[^0-9a-z]+/g, ".") +
".zip";
const output = fs.createWriteStream(
__dirname + "/out/" + archiveName
);
const archive = archiver("zip", {
zlib: { level: 9 }
});
archive.pipe(output);
// Add everything in the "dist" directory except for "svr.js" and "svr.compressed"
archive.glob("**/*", {
cwd: __dirname + "/dist",
ignore: ["svr.js", "svr.compressed"],
dot: true
});
// Create a stream for the "svr.compressed" file
const compressedSVRJSFileStream = fs
.createReadStream(__dirname + "/dist/svr.js")
.pipe(
zlib.createGzip({
level: 9
})
);
archive.append(compressedSVRJSFileStream, { name: "svr.compressed" });
archive.append(
'const zlib = require("zlib");\nconst fs = require("fs");\nconsole.log("Deleting SVR.JS stub...");\nfs.unlinkSync("svr.js");\nconsole.log("Decompressing SVR.JS...");\nconst script = zlib.gunzipSync(fs.readFileSync("svr.compressed"));\nfs.unlinkSync("svr.compressed");\nfs.writeFileSync("svr.js",script);\nconsole.log("Restart SVR.JS to get server interface.");',
{ name: "svr.js" }
);
archive.finalize();
})
.catch((err) => {
throw err;
});
})
.catch((err) => {
throw err;
});
} else {
// Bundle the source and copy the assets using esbuild and esbuild-plugin-copy with watching
esbuild
.context({
entryPoints: ["src/index.js"],
bundle: true,
outfile: "dist/svr.js",
platform: "node",
target: "es2017",
plugins: [
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
from: ["./assets/**/*"],
to: ["./dist"]
},
globbyOptions: {
dot: true
},
watch: {}
}),
esbuildCopyPlugin.copy({
resolveFrom: __dirname,
assets: {
from: ["./generatedAssets/**/*"],
to: ["./dist"]
},
watch: {}
})
]
})
.then((ctx) => {
ctx
.watch()
.then(() => {
const utilFilesAndDirectories = fs.existsSync(
__dirname + "/src/extraScripts"
)
? fs.readdirSync(__dirname + "/src/extraScripts")
: [];
const utilFiles = [];
utilFilesAndDirectories.forEach((entry) => {
if (fs.statSync(__dirname + "/src/extraScripts/" + entry).isFile())
utilFiles.push(entry);
});
// Transpile utilities using esbuild
esbuild
.context({
entryPoints: utilFiles.map(
(filename) => "src/extraScripts/" + filename
),
bundle: true,
outdir: "dist",
platform: "node",
target: "es2017"
})
.then((ctx) => {
ctx
.watch()
.then(() => {
console.log("Watching for changes in SVR.JS source code...");
})
.catch((err) => {
throw err;
});
})
.catch((err) => {
throw err;
});
})
.catch((err) => {
throw err;
});
})
.catch((err) => {
throw err;
});
}

6
nodemon.json Normal file
View file

@ -0,0 +1,6 @@
{
"watch": [
"dist/svr.js",
"dist/config.json"
]
}

1729
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,9 +3,10 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "node esbuild.config.js", "build": "npm run clean && NODE_ENV=production node esbuild.config.js",
"cz": "cz", "cz": "cz",
"dev": "npm run build && npm run start", "clean": "rimraf dist && rimraf out && rimraf generatedAssets",
"dev": "npm run clean && concurrently \"NODE_ENV=development node esbuild.config.js\" \"wait-on dist/svr.js && nodemon dist/svr.js --stdout-notty --no-save-config\"",
"lint": "eslint --no-error-on-unmatched-pattern src/**/*.js src/*.js tests/**/*.test.js tests/**/*.js tests/*.test.js tests/*.js", "lint": "eslint --no-error-on-unmatched-pattern src/**/*.js src/*.js tests/**/*.test.js tests/**/*.js tests/*.test.js tests/*.js",
"lint:fix": "npm run lint -- --fix", "lint:fix": "npm run lint -- --fix",
"prepare": "husky", "prepare": "husky",
@ -20,7 +21,9 @@
"@commitlint/config-conventional": "^19.4.1", "@commitlint/config-conventional": "^19.4.1",
"@eslint/js": "^9.9.0", "@eslint/js": "^9.9.0",
"archiver": "^7.0.1", "archiver": "^7.0.1",
"chokidar": "^4.0.1",
"commitizen": "^4.3.0", "commitizen": "^4.3.0",
"concurrently": "^9.1.0",
"cz-conventional-changelog": "^3.3.0", "cz-conventional-changelog": "^3.3.0",
"ejs": "^3.1.10", "ejs": "^3.1.10",
"esbuild": "^0.23.1", "esbuild": "^0.23.1",
@ -34,7 +37,10 @@
"jest": "^29.7.0", "jest": "^29.7.0",
"lint-staged": "^15.2.10", "lint-staged": "^15.2.10",
"node-mocks-http": "^1.15.1", "node-mocks-http": "^1.15.1",
"prettier": "^3.3.3" "nodemon": "^3.1.7",
"prettier": "^3.3.3",
"rimraf": "^5.0.10",
"wait-on": "^8.0.1"
}, },
"dependencies": { "dependencies": {
"formidable": "^2.1.2", "formidable": "^2.1.2",

View file

@ -12,6 +12,9 @@ let serverconsole = {};
function clientErrorHandler(err, socket) { function clientErrorHandler(err, socket) {
const config = deepClone(process.serverConfig); const config = deepClone(process.serverConfig);
// Determine the webroot from the current working directory if it is not configured
if (config.wwwroot === undefined) config.wwwroot = process.cwd();
config.generateServerString = () => config.generateServerString = () =>
generateServerString(config.exposeServerVersion); generateServerString(config.exposeServerVersion);
@ -182,14 +185,14 @@ function clientErrorHandler(err, socket) {
fs.access(config.page404, fs.constants.F_OK, (err) => { fs.access(config.page404, fs.constants.F_OK, (err) => {
if (err) { if (err) {
fs.access( fs.access(
"." + errorCode.toString(), config.wwwroot + "/." + errorCode.toString(),
fs.constants.F_OK, fs.constants.F_OK,
(err) => { (err) => {
try { try {
if (err) { if (err) {
callback(errorCode.toString() + ".html"); callback(errorCode.toString() + ".html");
} else { } else {
callback("." + errorCode.toString()); callback(config.wwwroot + "/." + errorCode.toString());
} }
} catch (err2) { } catch (err2) {
callServerError(500, err2); callServerError(500, err2);
@ -205,17 +208,21 @@ function clientErrorHandler(err, socket) {
} }
}); });
} else { } else {
fs.access("." + errorCode.toString(), fs.constants.F_OK, (err) => { fs.access(
try { config.wwwroot + "/." + errorCode.toString(),
if (err) { fs.constants.F_OK,
callback(errorCode.toString() + ".html"); (err) => {
} else { try {
callback("." + errorCode.toString()); if (err) {
callback(errorCode.toString() + ".html");
} else {
callback(config.wwwroot + "/." + errorCode.toString());
}
} catch (err2) {
callServerError(500, err2);
} }
} catch (err2) {
callServerError(500, err2);
} }
}); );
} }
} }
}; };
@ -457,15 +464,15 @@ function clientErrorHandler(err, socket) {
} sent invalid request.` } sent invalid request.`
); );
try { try {
head = fs.existsSync("./.head") head = fs.existsSync(`${config.wwwroot}/.head`)
? fs.readFileSync("./.head").toString() ? fs.readFileSync(`${config.wwwroot}/.head`).toString()
: fs.existsSync("./head.html") : fs.existsSync(`${config.wwwroot}/head.html`)
? fs.readFileSync("./head.html").toString() ? fs.readFileSync(`${config.wwwroot}/head.html`).toString()
: ""; // header : ""; // header
foot = fs.existsSync("./.foot") foot = fs.existsSync(`${config.wwwroot}/.foot`)
? fs.readFileSync("./.foot").toString() ? fs.readFileSync(`${config.wwwroot}/.foot`).toString()
: fs.existsSync("./foot.html") : fs.existsSync(`${config.wwwroot}/foot.html`)
? fs.readFileSync("./foot.html").toString() ? fs.readFileSync(`${config.wwwroot}/foot.html`).toString()
: ""; // footer : ""; // footer
if ( if (

View file

@ -32,6 +32,9 @@ function proxyHandler(req, socket, head) {
// SVR.JS configuration object (modified) // SVR.JS configuration object (modified)
const config = deepClone(process.serverConfig); const config = deepClone(process.serverConfig);
// Determine the webroot from the current working directory if it is not configured
if (config.wwwroot === undefined) config.wwwroot = process.cwd();
config.generateServerString = () => config.generateServerString = () =>
generateServerString(config.exposeServerVersion); generateServerString(config.exposeServerVersion);

View file

@ -37,6 +37,9 @@ function requestHandler(req, res) {
config.generateServerString = () => config.generateServerString = () =>
generateServerString(config.exposeServerVersion); generateServerString(config.exposeServerVersion);
// Determine the webroot from the current working directory if it is not configured
if (config.wwwroot === undefined) config.wwwroot = process.cwd();
// getCustomHeaders() in SVR.JS 3.x // getCustomHeaders() in SVR.JS 3.x
config.getCustomHeaders = () => { config.getCustomHeaders = () => {
let ph = Object.assign({}, config.customHeaders); let ph = Object.assign({}, config.customHeaders);
@ -345,14 +348,14 @@ function requestHandler(req, res) {
fs.access(config.page404, fs.constants.F_OK, (err) => { fs.access(config.page404, fs.constants.F_OK, (err) => {
if (err) { if (err) {
fs.access( fs.access(
"." + errorCode.toString(), config.wwwroot + "/." + errorCode.toString(),
fs.constants.F_OK, fs.constants.F_OK,
(err) => { (err) => {
try { try {
if (err) { if (err) {
callback(errorCode.toString() + ".html"); callback(errorCode.toString() + ".html");
} else { } else {
callback("." + errorCode.toString()); callback(config.wwwroot + "/." + errorCode.toString());
} }
} catch (err2) { } catch (err2) {
res.error(500, err2); res.error(500, err2);
@ -368,17 +371,21 @@ function requestHandler(req, res) {
} }
}); });
} else { } else {
fs.access("." + errorCode.toString(), fs.constants.F_OK, (err) => { fs.access(
try { config.wwwroot + "/." + errorCode.toString(),
if (err) { fs.constants.F_OK,
callback(errorCode.toString() + ".html"); (err) => {
} else { try {
callback("." + errorCode.toString()); if (err) {
callback(errorCode.toString() + ".html");
} else {
callback(config.wwwroot + "/." + errorCode.toString());
}
} catch (err2) {
res.error(500, err2);
} }
} catch (err2) {
res.error(500, err2);
} }
}); );
} }
} }
}; };
@ -633,15 +640,15 @@ function requestHandler(req, res) {
}; };
try { try {
res.head = fs.existsSync("./.head") res.head = fs.existsSync(`${config.wwwroot}/.head`)
? fs.readFileSync("./.head").toString() ? fs.readFileSync(`${config.wwwroot}/.head`).toString()
: fs.existsSync("./head.html") : fs.existsSync(`${config.wwwroot}/head.html`)
? fs.readFileSync("./head.html").toString() ? fs.readFileSync(`${config.wwwroot}/head.html`).toString()
: ""; // header : ""; // header
res.foot = fs.existsSync("./.foot") res.foot = fs.existsSync(`${config.wwwroot}/.foot`)
? fs.readFileSync("./.foot").toString() ? fs.readFileSync(`${config.wwwroot}/.foot`).toString()
: fs.existsSync("./foot.html") : fs.existsSync(`${config.wwwroot}/foot.html`)
? fs.readFileSync("./foot.html").toString() ? fs.readFileSync(`${config.wwwroot}/foot.html`).toString()
: ""; // footer : ""; // footer
} catch (err) { } catch (err) {
res.error(500, err); res.error(500, err);

View file

@ -117,7 +117,7 @@ if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into pr
function printUsage() { function printUsage() {
console.log(`${name} usage:`); console.log(`${name} usage:`);
console.log( console.log(
"node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [-v] [--version]" "node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [--stdout-notty] [--no-save-config] [-v] [--version]"
); );
console.log("-h -? /h /? --help -- Displays help"); console.log("-h -? /h /? --help -- Displays help");
console.log("--clean -- Cleans up files created by " + name); console.log("--clean -- Cleans up files created by " + name);
@ -127,12 +127,18 @@ function printUsage() {
console.log("--secure -- Runs HTTPS server"); console.log("--secure -- Runs HTTPS server");
console.log("--disable-mods -- Disables mods (safe mode)"); console.log("--disable-mods -- Disables mods (safe mode)");
console.log("--single-threaded -- Run single-threaded"); console.log("--single-threaded -- Run single-threaded");
console.log(
"--stdout-notty -- Enable stdout even when stdout is not a TTY. May decrease the performace"
);
console.log("--no-save-config -- Don't save configuration file");
console.log("-v --version -- Display server version"); console.log("-v --version -- Display server version");
} }
let exiting = false; let exiting = false;
let forceSecure = false; let forceSecure = false;
let disableMods = false; let disableMods = false;
let stdoutNoTTY = false;
let noSaveConfig = false;
// Handle command line arguments // Handle command line arguments
const args = process.argv; const args = process.argv;
@ -184,6 +190,10 @@ for (
disableMods = true; disableMods = true;
} else if (args[i] == "--single-threaded") { } else if (args[i] == "--single-threaded") {
process.singleThreaded = true; process.singleThreaded = true;
} else if (args[i] == "--stdout-notty") {
stdoutNoTTY = true;
} else if (args[i] == "--no-save-config") {
noSaveConfig = true;
} else { } else {
console.log(`Unrecognized argument: ${args[i]}`); console.log(`Unrecognized argument: ${args[i]}`);
printUsage(); printUsage();
@ -329,6 +339,11 @@ if (process.serverConfig.allowPostfixDoubleSlashes === undefined)
process.serverConfig.allowPostfixDoubleSlashes = false; process.serverConfig.allowPostfixDoubleSlashes = false;
if (process.serverConfig.optOutOfStatisticsServer === undefined) if (process.serverConfig.optOutOfStatisticsServer === undefined)
process.serverConfig.optOutOfStatisticsServer = false; process.serverConfig.optOutOfStatisticsServer = false;
if (process.serverConfig.disableConfigurationSaving === undefined)
process.serverConfig.disableConfigurationSaving = false;
// Don't save configuration if disableConfigurationSaving option is set to true
if (process.serverConfig.disableConfigurationSaving) noSaveConfig = true;
// Compatiblity for very old SVR.JS mods // Compatiblity for very old SVR.JS mods
process.serverConfig.version = version; process.serverConfig.version = version;
@ -385,7 +400,7 @@ try {
// Failed to get inspector URL // Failed to get inspector URL
} }
if (!process.stdout.isTTY && !inspectorURL) { if (!stdoutNoTTY && !process.stdout.isTTY && !inspectorURL) {
// When stdout is not a terminal and not attached to an Node.JS inspector, disable it to improve performance of SVR.JS // When stdout is not a terminal and not attached to an Node.JS inspector, disable it to improve performance of SVR.JS
console.log = () => {}; console.log = () => {};
process.stdout.write = () => {}; process.stdout.write = () => {};
@ -797,7 +812,11 @@ if (!disableMods) {
} }
// Determine path of server-side script file // Determine path of server-side script file
let SSJSPath = "./serverSideScript.js"; let SSJSPath = `${
process.serverConfig.wwwroot != undefined
? process.serverConfig.wwwroot
: process.dirname
}/serverSideScript.js`;
if (!process.serverConfig.useWebRootServerSideScript) if (!process.serverConfig.useWebRootServerSideScript)
SSJSPath = process.dirname + "/serverSideScript.js"; SSJSPath = process.dirname + "/serverSideScript.js";
@ -1686,6 +1705,8 @@ function saveConfig() {
configJSONobj.allowDoubleSlashes = false; configJSONobj.allowDoubleSlashes = false;
if (configJSONobj.optOutOfStatisticsServer === undefined) if (configJSONobj.optOutOfStatisticsServer === undefined)
configJSONobj.optOutOfStatisticsServer = false; configJSONobj.optOutOfStatisticsServer = false;
if (configJSONobj.disableConfigurationSaving === undefined)
configJSONobj.disableConfigurationSaving = false;
fs.writeFileSync( fs.writeFileSync(
process.dirname + "/config.json", process.dirname + "/config.json",
@ -1978,69 +1999,73 @@ function start(init) {
let workersToFork = 1; let workersToFork = 1;
if (cluster.isPrimary === undefined) { if (cluster.isPrimary === undefined) {
setInterval(() => { if (!noSaveConfig) {
try { setInterval(() => {
saveConfig();
serverconsole.locmessage("Configuration saved.");
} catch (err) {
throw new Error(err);
}
}, 300000);
} else if (cluster.isPrimary) {
setInterval(() => {
let allWorkers = Object.keys(cluster.workers);
let goodWorkers = [];
const checkWorker = (callback, _id) => {
if (typeof _id === "undefined") _id = 0;
if (_id >= allWorkers.length) {
callback();
return;
}
try { try {
if (cluster.workers[allWorkers[_id]]) { saveConfig();
isWorkerHungUpBuff2 = true; serverconsole.locmessage("Configuration saved.");
cluster.workers[allWorkers[_id]].on("message", msgListener); } catch (err) {
cluster.workers[allWorkers[_id]].send("\x14PINGPING"); throw new Error(err);
setTimeout(() => { }
if (isWorkerHungUpBuff2) { }, 300000);
checkWorker(callback, _id + 1); }
} else { } else if (cluster.isPrimary) {
goodWorkers.push(allWorkers[_id]); if (!noSaveConfig) {
checkWorker(callback, _id + 1); setInterval(() => {
} let allWorkers = Object.keys(cluster.workers);
}, 250); let goodWorkers = [];
} else {
const checkWorker = (callback, _id) => {
if (typeof _id === "undefined") _id = 0;
if (_id >= allWorkers.length) {
callback();
return;
}
try {
if (cluster.workers[allWorkers[_id]]) {
isWorkerHungUpBuff2 = true;
cluster.workers[allWorkers[_id]].on("message", msgListener);
cluster.workers[allWorkers[_id]].send("\x14PINGPING");
setTimeout(() => {
if (isWorkerHungUpBuff2) {
checkWorker(callback, _id + 1);
} else {
goodWorkers.push(allWorkers[_id]);
checkWorker(callback, _id + 1);
}
}, 250);
} else {
checkWorker(callback, _id + 1);
}
// eslint-disable-next-line no-unused-vars
} catch (err) {
if (cluster.workers[allWorkers[_id]]) {
cluster.workers[allWorkers[_id]].removeAllListeners("message");
addListenersToWorker(cluster.workers[allWorkers[_id]]);
}
checkWorker(callback, _id + 1); checkWorker(callback, _id + 1);
} }
// eslint-disable-next-line no-unused-vars };
} catch (err) { checkWorker(() => {
if (cluster.workers[allWorkers[_id]]) { const wN = Math.floor(Math.random() * goodWorkers.length); //Send a configuration saving message to a random worker.
cluster.workers[allWorkers[_id]].removeAllListeners("message"); try {
addListenersToWorker(cluster.workers[allWorkers[_id]]); if (cluster.workers[goodWorkers[wN]]) {
isWorkerHungUpBuff2 = true;
cluster.workers[goodWorkers[wN]].on("message", msgListener);
cluster.workers[goodWorkers[wN]].send("\x14SAVECONF");
}
} catch (err) {
if (cluster.workers[goodWorkers[wN]]) {
cluster.workers[goodWorkers[wN]].removeAllListeners("message");
addListenersToWorker(cluster.workers[goodWorkers[wN]]);
}
serverconsole.locwarnmessage(
`There was a problem while saving configuration file. Reason: ${err.message}`
);
} }
checkWorker(callback, _id + 1); });
} }, 300000);
}; }
checkWorker(() => {
const wN = Math.floor(Math.random() * goodWorkers.length); //Send a configuration saving message to a random worker.
try {
if (cluster.workers[goodWorkers[wN]]) {
isWorkerHungUpBuff2 = true;
cluster.workers[goodWorkers[wN]].on("message", msgListener);
cluster.workers[goodWorkers[wN]].send("\x14SAVECONF");
}
} catch (err) {
if (cluster.workers[goodWorkers[wN]]) {
cluster.workers[goodWorkers[wN]].removeAllListeners("message");
addListenersToWorker(cluster.workers[goodWorkers[wN]]);
}
serverconsole.locwarnmessage(
`There was a problem while saving configuration file. Reason: ${err.message}`
);
}
});
}, 300000);
} }
if (!cluster.isPrimary && cluster.isPrimary !== undefined) { if (!cluster.isPrimary && cluster.isPrimary !== undefined) {
@ -2429,7 +2454,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
process.on("exit", (code) => { process.on("exit", (code) => {
try { try {
if (!configJSONRErr && !configJSONPErr) { if (!configJSONRErr && !configJSONPErr && !noSaveConfig) {
saveConfig(); saveConfig();
} }
} catch (err) { } catch (err) {

View file

@ -8,8 +8,12 @@ const {
} = require("../utils/forbiddenPaths.js"); } = require("../utils/forbiddenPaths.js");
const svrjsInfo = require("../../svrjs.json"); const svrjsInfo = require("../../svrjs.json");
const { name } = svrjsInfo; const { name } = svrjsInfo;
const wwwroot =
process.serverConfig && process.serverConfig.wwwroot !== undefined
? process.serverConfig.wwwroot
: ".";
forbiddenPaths.config = getInitializePath("./config.json"); forbiddenPaths.config = getInitializePath(`${wwwroot}/config.json`);
forbiddenPaths.certificates = []; forbiddenPaths.certificates = [];
if (process.serverConfig.secure) { if (process.serverConfig.secure) {
forbiddenPaths.certificates.push( forbiddenPaths.certificates.push(
@ -26,7 +30,8 @@ if (process.serverConfig.secure) {
}); });
} }
forbiddenPaths.svrjs = getInitializePath( forbiddenPaths.svrjs = getInitializePath(
"./" + wwwroot +
"/" +
(process.dirname[process.dirname.length - 1] != "/" (process.dirname[process.dirname.length - 1] != "/"
? process.filename.replace(process.dirname + "/", "") ? process.filename.replace(process.dirname + "/", "")
: process.filename.replace(process.dirname, "")) : process.filename.replace(process.dirname, ""))
@ -36,16 +41,18 @@ if (process.serverConfig.useWebRootServerSideScript) {
forbiddenPaths.serverSideScripts.push("/serverSideScript.js"); forbiddenPaths.serverSideScripts.push("/serverSideScript.js");
} else { } else {
forbiddenPaths.serverSideScripts.push( forbiddenPaths.serverSideScripts.push(
getInitializePath("./serverSideScript.js") getInitializePath(`${wwwroot}/serverSideScript.js`)
); );
} }
forbiddenPaths.serverSideScriptDirectories = []; forbiddenPaths.serverSideScriptDirectories = [];
forbiddenPaths.serverSideScriptDirectories.push( forbiddenPaths.serverSideScriptDirectories.push(
getInitializePath("./node_modules") getInitializePath(`${wwwroot}/node_modules`)
); );
forbiddenPaths.serverSideScriptDirectories.push(getInitializePath("./mods")); forbiddenPaths.serverSideScriptDirectories.push(
forbiddenPaths.temp = getInitializePath("./temp"); getInitializePath(wwwroot + "/mods")
forbiddenPaths.log = getInitializePath("./log"); );
forbiddenPaths.temp = getInitializePath(`${wwwroot}/temp`);
forbiddenPaths.log = getInitializePath(`${wwwroot}/log`);
module.exports = (req, res, logFacilities, config, next) => { module.exports = (req, res, logFacilities, config, next) => {
let decodedHrefWithoutDuplicateSlashes = ""; let decodedHrefWithoutDuplicateSlashes = "";

View file

@ -9,22 +9,25 @@ module.exports = (req, res, logFacilities, config, next) => {
req.originalParsedURL.pathname[req.originalParsedURL.pathname.length - 1] != req.originalParsedURL.pathname[req.originalParsedURL.pathname.length - 1] !=
"/" "/"
) { ) {
fs.stat("." + decodeURIComponent(req.parsedURL.pathname), (err, stats) => { fs.stat(
if (err || !stats.isDirectory()) { config.wwwroot + decodeURIComponent(req.parsedURL.pathname),
try { (err, stats) => {
next(); if (err || !stats.isDirectory()) {
} catch (err) { try {
res.error(500, err); next();
} catch (err) {
res.error(500, err);
}
} else {
res.redirect(
req.originalParsedURL.pathname +
"/" +
(req.parsedURL.search ? req.parsedURL.search : "") +
(req.parsedURL.hash ? req.parsedURL.hash : "")
);
} }
} else {
res.redirect(
req.originalParsedURL.pathname +
"/" +
(req.parsedURL.search ? req.parsedURL.search : "") +
(req.parsedURL.hash ? req.parsedURL.hash : "")
);
} }
}); );
} else { } else {
next(); next();
} }

View file

@ -28,7 +28,7 @@ module.exports = (req, res, logFacilities, config, next) => {
!_fileState !_fileState
) { ) {
fs.stat( fs.stat(
"." + decodeURIComponent(req.parsedURL.pathname), config.wwwroot + decodeURIComponent(req.parsedURL.pathname),
(err, stats) => { (err, stats) => {
let _fileState = 3; let _fileState = 3;
if (err) { if (err) {

View file

@ -86,7 +86,7 @@ module.exports = (req, res, logFacilities, config, next) => {
res.error(400); res.error(400);
return; return;
} }
let readFrom = "." + dHref; let readFrom = config.wwwroot + dHref;
let dirImagesMissing = false; let dirImagesMissing = false;
fs.stat(readFrom, (err, stats) => { fs.stat(readFrom, (err, stats) => {
if (err) { if (err) {
@ -502,13 +502,16 @@ module.exports = (req, res, logFacilities, config, next) => {
const getCustomDirListingHeader = (callback) => { const getCustomDirListingHeader = (callback) => {
fs.readFile( fs.readFile(
("." + dHref + "/.dirhead").replace(/\/+/g, "/"), (config.wwwroot + dHref + "/.dirhead").replace(/\/+/g, "/"),
(err, data) => { (err, data) => {
if (err) { if (err) {
if (err.code == "ENOENT" || err.code == "EISDIR") { if (err.code == "ENOENT" || err.code == "EISDIR") {
if (os.platform != "win32" || href != "/") { if (os.platform != "win32" || href != "/") {
fs.readFile( fs.readFile(
("." + dHref + "/HEAD.html").replace(/\/+/g, "/"), (config.wwwroot + dHref + "/HEAD.html").replace(
/\/+/g,
"/"
),
(err, data) => { (err, data) => {
if (err) { if (err) {
if (err.code == "ENOENT" || err.code == "EISDIR") { if (err.code == "ENOENT" || err.code == "EISDIR") {
@ -538,13 +541,16 @@ module.exports = (req, res, logFacilities, config, next) => {
const getCustomDirListingFooter = (callback) => { const getCustomDirListingFooter = (callback) => {
fs.readFile( fs.readFile(
("." + dHref + "/.dirfoot").replace(/\/+/g, "/"), (config.wwwroot + dHref + "/.dirfoot").replace(/\/+/g, "/"),
(err, data) => { (err, data) => {
if (err) { if (err) {
if (err.code == "ENOENT" || err.code == "EISDIR") { if (err.code == "ENOENT" || err.code == "EISDIR") {
if (os.platform != "win32" || href != "/") { if (os.platform != "win32" || href != "/") {
fs.readFile( fs.readFile(
("." + dHref + "/FOOT.html").replace(/\/+/g, "/"), (config.wwwroot + dHref + "/FOOT.html").replace(
/\/+/g,
"/"
),
(err, data) => { (err, data) => {
if (err) { if (err) {
if (err.code == "ENOENT" || err.code == "EISDIR") { if (err.code == "ENOENT" || err.code == "EISDIR") {
@ -646,7 +652,7 @@ module.exports = (req, res, logFacilities, config, next) => {
if ( if (
fs.existsSync( fs.existsSync(
"." + config.wwwroot +
decodeURIComponent(href) + decodeURIComponent(href) +
"/.maindesc".replace(/\/+/g, "/") "/.maindesc".replace(/\/+/g, "/")
) )
@ -654,7 +660,7 @@ module.exports = (req, res, logFacilities, config, next) => {
htmlFoot = htmlFoot =
"</table><hr/>" + "</table><hr/>" +
fs.readFileSync( fs.readFileSync(
"." + config.wwwroot +
decodeURIComponent(href) + decodeURIComponent(href) +
"/.maindesc".replace(/\/+/g, "/") "/.maindesc".replace(/\/+/g, "/")
) + ) +

View file

@ -1,9 +1,9 @@
{ {
"version": "4.1.0", "version": "Nightly-GitNext",
"name": "SVR.JS", "name": "SVR.JS",
"documentationURL": "https://svrjs.org/docs", "documentationURL": "https://svrjs.org/docs",
"statisticsServerCollectEndpoint": "https://statistics.svrjs.org/collect.svr", "statisticsServerCollectEndpoint": "https://statistics.svrjs.org/collect.svr",
"changes": [ "changes": [
"Added experimental support for Deno 2." "INSERT CHANGES THERE"
] ]
} }

View file

@ -73,7 +73,8 @@
"disableTrailingSlashRedirects": false, "disableTrailingSlashRedirects": false,
"environmentVariables": {}, "environmentVariables": {},
"allowDoubleSlashes": false, "allowDoubleSlashes": false,
"optOutOfStatisticsServer": false "optOutOfStatisticsServer": false,
"disableConfigurationSaving": false
}</pre> }</pre>
</code> </code>
<p>Changes:</p> <p>Changes:</p>

View file

@ -1,8 +1,8 @@
const middleware = require("../../src/utils/ipBlockList.js"); const middleware = require("../../src/utils/ipBlockList.js");
const cluster = require("../../src/utils/clusterBunShim.js"); const cluster = require("../../src/utils/clusterShim.js");
jest.mock("../../src/utils/ipBlockList.js"); jest.mock("../../src/utils/ipBlockList.js");
jest.mock("../../src/utils/clusterBunShim.js"); jest.mock("../../src/utils/clusterShim.js");
const ipBlockListAdd = jest.fn(); const ipBlockListAdd = jest.fn();
const ipBlockListCheck = jest.fn(); const ipBlockListCheck = jest.fn();

View file

@ -2,13 +2,13 @@ const sha256 = require("../../src/utils/sha256.js");
const ipMatch = require("../../src/utils/ipMatch.js"); const ipMatch = require("../../src/utils/ipMatch.js");
const matchHostname = require("../../src/utils/matchHostname.js"); const matchHostname = require("../../src/utils/matchHostname.js");
const ipBlockList = require("../../src/utils/ipBlockList.js"); const ipBlockList = require("../../src/utils/ipBlockList.js");
const cluster = require("../../src/utils/clusterBunShim.js"); const cluster = require("../../src/utils/clusterShim.js");
jest.mock("../../src/utils/sha256.js"); jest.mock("../../src/utils/sha256.js");
jest.mock("../../src/utils/ipMatch.js"); jest.mock("../../src/utils/ipMatch.js");
jest.mock("../../src/utils/matchHostname.js"); jest.mock("../../src/utils/matchHostname.js");
jest.mock("../../src/utils/ipBlockList.js"); jest.mock("../../src/utils/ipBlockList.js");
jest.mock("../../src/utils/clusterBunShim.js"); jest.mock("../../src/utils/clusterShim.js");
let mockScryptHash = "mocked-scrypt-hash"; let mockScryptHash = "mocked-scrypt-hash";
let mockPbkdf2Hash = "mocked-pbkdf2-hash"; let mockPbkdf2Hash = "mocked-pbkdf2-hash";