forked from svrjs/svrjs
chore: remove "version" property from "svrjs.core.json" and create SVR.JS Core documentation
This commit is contained in:
parent
e0536620d6
commit
79b506a4f0
5 changed files with 74 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -1,3 +1,64 @@
|
|||
# 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
|
|
@ -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) => {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue