1
0
Fork 0
forked from svrjs/svrjs

chore: remove "version" property from "svrjs.core.json" and create SVR.JS Core documentation

This commit is contained in:
Dorian Niemiec 2024-11-10 16:38:06 +01:00
parent e0536620d6
commit 79b506a4f0
5 changed files with 74 additions and 8 deletions

View file

@ -81,7 +81,7 @@ After installing the packages, build SVR.JS with this command:
```bash ```bash
npm run build 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) ## 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: The file structure for SVR.JS source code looks like this:
- .husky - Git hooks - .husky - Git hooks
- assets - files to copy into dist folder and to the archive - 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 - dist - contains SVR.JS, assets, and SVR.JS utiltiies
- generatedAssets - assets generated by the build script - generatedAssets - assets generated by the build script
- out - contains SVR.JS zip archive - out - contains SVR.JS zip archive

View file

@ -1,3 +1,64 @@
# SVR.JS Core # SVR.JS Core
TODO 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

View file

@ -11,7 +11,6 @@ const svrjsCoreInfo = JSON.parse(
fs.readFileSync(__dirname + "/svrjs.core.json") fs.readFileSync(__dirname + "/svrjs.core.json")
); );
const { externalPackages } = svrjsCoreInfo; const { externalPackages } = svrjsCoreInfo;
const coreVersion = svrjsCoreInfo.version;
const corePackageJSON = svrjsCoreInfo.packageJSON; const corePackageJSON = svrjsCoreInfo.packageJSON;
const isDev = process.env.NODE_ENV == "development"; const isDev = process.env.NODE_ENV == "development";
@ -265,7 +264,7 @@ if (!isDev) {
const packageJSON = Object.assign({}, corePackageJSON); const packageJSON = Object.assign({}, corePackageJSON);
// Add package.json properties // Add package.json properties
packageJSON.version = coreVersion; packageJSON.version = version;
packageJSON.main = "./svr.core.js"; packageJSON.main = "./svr.core.js";
packageJSON.dependencies = coreDependencyNames.reduce( packageJSON.dependencies = coreDependencyNames.reduce(
(previousDependencies, dependency) => { (previousDependencies, dependency) => {

View file

@ -1,5 +1,7 @@
const svrjsInfo = require("../../svrjs.core.json"); const svrjsCoreInfo = require("../../svrjs.core.json");
const { version, name } = svrjsInfo; const { name } = svrjsCoreInfo;
const svrjsInfo = require("../../svrjs.json");
const { version } = svrjsInfo;
const getOS = require("./getOS.js"); const getOS = require("./getOS.js");
function generateServerString(exposeServerVersion) { function generateServerString(exposeServerVersion) {

View file

@ -1,5 +1,4 @@
{ {
"version": "Nightly-GitNext",
"name": "SVR.JS Core", "name": "SVR.JS Core",
"externalPackages": ["mime-types"], "externalPackages": ["mime-types"],
"packageJSON": { "packageJSON": {
@ -18,6 +17,9 @@
"middleware" "middleware"
], ],
"homepage": "https://svrjs.org", "homepage": "https://svrjs.org",
"license": "MIT" "license": "MIT",
"engines": {
"node": ">=10.0.0"
}
} }
} }