1
0
Fork 0
forked from svrjs/svrjs
This repository has been archived on 2024-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs/coreAssets
2024-11-10 16:38:06 +01:00
..
LICENSE feat: add SVR.JS Core 2024-11-10 15:42:56 +01:00
README.md chore: remove "version" property from "svrjs.core.json" and create SVR.JS Core documentation 2024-11-10 16:38:06 +01:00

SVR.JS Core

SVR.JS Core is a library for static file serving, built from SVR.JS source code.

Example code (with Node.JS "http" module):

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):

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.

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