From 79b506a4f0f1f276f688c6e2a929289a84645c34 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sun, 10 Nov 2024 16:38:06 +0100 Subject: [PATCH] chore: remove "version" property from "svrjs.core.json" and create SVR.JS Core documentation --- README.md | 4 +- coreAssets/README.md | 63 ++++++++++++++++++++++++++- esbuild.config.js | 3 +- src/utils/generateServerStringCore.js | 6 ++- svrjs.core.json | 6 ++- 5 files changed, 74 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f85c0f7..261114c 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ After installing the packages, build SVR.JS with this command: ```bash npm run build ``` -After running the command, you will get bundled SVR.JS script, around with built-in utilities and assets in the `dist` directory. You will also get a zip archive in `out` directory, that can be installed using SVR.JS installer +After running the command, you will get bundled SVR.JS script, around with built-in utilities and assets in the `dist` directory. You will also get a zip archive in `out` directory, that can be installed using SVR.JS installer. Additionally, you will get the SVR.JS Core package contents in the `core` directory, which you can publish by running `npm publish` in the `core` directory. ## Installation (built from source) @@ -118,6 +118,8 @@ You can read the [SVR.JS documentation](https://svrjs.org/docs) to get informati The file structure for SVR.JS source code looks like this: - .husky - Git hooks - assets - files to copy into dist folder and to the archive + - core - contains SVR.JS Core + - coreAssets - files to copy into core folder - dist - contains SVR.JS, assets, and SVR.JS utiltiies - generatedAssets - assets generated by the build script - out - contains SVR.JS zip archive diff --git a/coreAssets/README.md b/coreAssets/README.md index cf1ff04..0d79b91 100644 --- a/coreAssets/README.md +++ b/coreAssets/README.md @@ -1,3 +1,64 @@ # SVR.JS Core -TODO \ No newline at end of file +SVR.JS Core is a library for static file serving, built from SVR.JS source code. + +Example code (with Node.JS "http" module): +```javascript +var http = require("http"); +var fs = require("fs"); +var url = require("url"); +var svrjsCore = require("svrjs-core").init(); // Initialize SVR.JS Core +var server = http.createServer(function (req,res) { + if(url.parse(req.url).pathname == "/useragent") { + res.writeHead(200, "OK", {"content-type": "text-plain"}); // Output as plain text + res.end("Your user agent: " + req.headers["user-agent"]); // Send user agent + } else { + svrjsCore(req,res); // Serve static content + } +}).listen(8888); +``` + +Example code (with Express): +```javascript +var express = require("express"); +var svrjsCore = require("svrjs-core"); + +var app = express(); +app.use(svrjsCore()); + +app.listen(3000); +``` + +## Methods + +### *svrjsCore([config])* + +Parameters: + +- *config* - the SVR.JS Core configuration (optional, *Object*) + +Returns: the request handler for use in Node.JS HTTP server or Express, with three parameters (*req*, *res*, and optional *next*) + +The *config* object is almost the same format as SVR.JS configuration. You can read about SVR.JS configuration properties in [the SVR.JS documentation](https://svrjs.org/docs/config/configuration). + +However, only these SVR.JS configuration properties apply to SVR.JS Core: +- *users* +- *page404* +- *enableCompression* +- *customHeaders* +- *enableDirectoryListing* +- *enableDirectoryListingWithDefaultHead* +- *serverAdministratorEmail* +- *stackHidden* +- *exposeServerVersion* +- *dontCompress* +- *enableIPSpoofing* +- *enableETag* +- *rewriteDirtyURLs* +- *errorPages* +- *disableTrailingSlashRedirects* +- *allowDoubleSlashes* + +### *svrjsCore.init([config])* + +An alias to the *svrjsCore()* function \ No newline at end of file diff --git a/esbuild.config.js b/esbuild.config.js index b97a268..2daed75 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -11,7 +11,6 @@ const svrjsCoreInfo = JSON.parse( fs.readFileSync(__dirname + "/svrjs.core.json") ); const { externalPackages } = svrjsCoreInfo; -const coreVersion = svrjsCoreInfo.version; const corePackageJSON = svrjsCoreInfo.packageJSON; const isDev = process.env.NODE_ENV == "development"; @@ -265,7 +264,7 @@ if (!isDev) { const packageJSON = Object.assign({}, corePackageJSON); // Add package.json properties - packageJSON.version = coreVersion; + packageJSON.version = version; packageJSON.main = "./svr.core.js"; packageJSON.dependencies = coreDependencyNames.reduce( (previousDependencies, dependency) => { diff --git a/src/utils/generateServerStringCore.js b/src/utils/generateServerStringCore.js index 7d8a227..6617740 100644 --- a/src/utils/generateServerStringCore.js +++ b/src/utils/generateServerStringCore.js @@ -1,5 +1,7 @@ -const svrjsInfo = require("../../svrjs.core.json"); -const { version, name } = svrjsInfo; +const svrjsCoreInfo = require("../../svrjs.core.json"); +const { name } = svrjsCoreInfo; +const svrjsInfo = require("../../svrjs.json"); +const { version } = svrjsInfo; const getOS = require("./getOS.js"); function generateServerString(exposeServerVersion) { diff --git a/svrjs.core.json b/svrjs.core.json index 22b8984..c7a8c4e 100644 --- a/svrjs.core.json +++ b/svrjs.core.json @@ -1,5 +1,4 @@ { - "version": "Nightly-GitNext", "name": "SVR.JS Core", "externalPackages": ["mime-types"], "packageJSON": { @@ -18,6 +17,9 @@ "middleware" ], "homepage": "https://svrjs.org", - "license": "MIT" + "license": "MIT", + "engines": { + "node": ">=10.0.0" + } } }