SGAppsServer

SGAppsServer

new SGAppsServer(optionsopt)

Source:

HTTP Server for high performance results

Examples
// ================================
//   Start your ๐Ÿš€ Web-Server app
// ================================

const { SGAppsServer } = require('@sgapps.io/server');
const app = new SGAppsServer();

app.get('/', function (req, res) {
  res.send('hello world')
})

app.server().listen(8080, () => {
  app.logger.log('Server is running on port 8080');
})
// ========================================
//   Start your ๐Ÿš€ Web-Server app Extended
// ========================================

const { SGAppsServer } = require('@sgapps.io/server');
const app = new SGAppsServer();

app.get('/', function (req, res) {
  res.send('hello world')
})

app.whenReady.then(() => {
  app.SessionManager.cookie = 'ssid';
  app.SessionManager.SESSION_LIFE = 120; // seconds

  app.server().listen(8080, () => {
    app.logger.log('Server is running on port 8080');
  })
}, app.logger.error);
Parameters:
Name Type Attributes Description
options object <optional>
Properties
Name Type Attributes Default Description
server Server <optional>
strictRouting boolean <optional>
true
debug boolean <optional>
true
_DEBUG_MAX_HANDLER_EXECUTION_TIME object <optional>
500

console shows an warn if handler is executed more than ( works in debug mode )

_DEBUG_REQUEST_HANDLERS_STATS object <optional>
false

console shows an warn if handler is executed more than ( works in debug mode )

_REQUEST_FORM_PARAMS_DEEP_PARSE boolean <optional>
true

parse formData field names to create deep object request.body

decorators Array.<SGAppsServerDecorator> <optional>

Classes

NodeJsMvc

Members

_decorators :Array.<SGAppsServerDecorator>

Source:
Type:

_fs :object

Source:
Type:
  • object

_options :SGAppsServerOptions

Source:
Type:

_path :object

Source:
Type:
  • object

_requestListeners :Object.<string, SGAppsServerDictionary>

Source:
Type:

_server :Server

Source:
Type:
  • Server

AccessLogger :AccessLogger

Source:
Type:

AccessLoggerPaths :Object.<string, AccessLogger.AccessLoggerPath>

Source:
Type:

CookiesManager :object

Source:
Properties:
Name Type Attributes Default Description
COOKIES_KEY string
_enabled boolean <optional>
true

if is changed to false server will not decorate requests with cookie manager

handle function
Type:
  • object

EXTENSIONS :ResourcesExtensions

Source:
Type:

logger :LoggerBuilder

Source:
Type:

MAX_POST_SIZE :number

Source:

default value is 16 Kb ยป 16 * 1024

Type:
  • number

mountPath :string

Source:
Type:
  • string

NodeJsMvc :SGAppsServer.NodeJsMvc

Source:
Type:

SessionManager :SGAppsSessionManager

Source:
Type:

shared :SGAppsServerShared

Source:
Type:

STATUS_CODES :Object.<number, string>

Source:
Type:
  • Object.<number, string>

TemplateManager :TemplateManager

Source:
Type:

whenReady :Promise.<SGAppsServer>

Source:
Type:

Methods

all(path, …handlers) → {SGAppsServer}

Source:

add handler to all methods

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

connect(path, …handlers) → {SGAppsServer}

Source:

The CONNECT method establishes a tunnel to the server identified by the target resource.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

delete(path, …handlers) → {SGAppsServer}

Source:

The DELETE method deletes the specified resource.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

Email(config) → {SGAppsServerEmail}

Source:
Parameters:
Name Type Description
config SGAppsServerEmail.Config
Returns:
Type
SGAppsServerEmail

finalHandler(path, …handlers) → {SGAppsServer}

Source:

add final handler to all methods, last added is first

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

get(path, …handlers) → {SGAppsServer}

Source:

The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

handle(request, response, callbackopt)

Source:
Parameters:
Name Type Attributes Description
request IncomingMessage
response ServerResponse
callback SGAppsServerDictionaryRunCallBack <optional>

handleErrorRequest(request, response, erropt)

Source:
Parameters:
Name Type Attributes Description
request SGAppsServerRequest
response SGAppsServerResponse
err Error <optional>

handlePostData(optionsopt) → {SGAppsServerHandlerPostData}

Source:
Parameters:
Name Type Attributes Description
options object <optional>
Properties
Name Type Attributes Description
MAX_POST_SIZE number <optional>
error object <optional>
Properties
Name Type Attributes Description
statusCode number
message string <optional>
Returns:
Type
SGAppsServerHandlerPostData

handleRequest(request, response, callback)

Source:
Parameters:
Name Type Description
request SGAppsServerRequest
response SGAppsServerResponse
callback SGAppsServerDictionaryRunCallBack

handleStaticRequest(request, response, path, callback, optionsopt)

Source:
Parameters:
Name Type Attributes Description
request SGAppsServerRequest
response SGAppsServerResponse
path string
callback SGAppsServerErrorCallBack
options object <optional>
Properties
Name Type Attributes Default Description
timeout number <optional>
0
autoIndex Array.<string> <optional>

list of auto-index files, ex: ['index.html', 'index.htm', 'default.html']

Source:

The HEAD method asks for a response identical to that of a GET request, but without the response body.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

options(path, …handlers) → {SGAppsServer}

Source:

The OPTIONS method is used to describe the communication options for the target resource.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

patch(path, …handlers) → {SGAppsServer}

Source:

The PATCH method is used to apply partial modifications to a resource.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

post(path, …handlers) → {SGAppsServer}

Source:

The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

put(path, …handlers) → {SGAppsServer}

Source:

The PUT method replaces all current representations of the target resource with the request payload.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

server() → {Server}

Source:
Returns:
Type
Server

trace(path, …handlers) → {SGAppsServer}

Source:

The TRACE method performs a message loop-back test along the path to the target resource.

Parameters:
Name Type Attributes Description
path RequestPathStructure
handlers RequestHandler <repeatable>
Returns:
Type
SGAppsServer

use(path, …handlersopt) → {SGAppsServer}

Source:
Parameters:
Name Type Attributes Description
path string | RequestHandler
handlers RequestHandler <optional>
<repeatable>
Returns:
Type
SGAppsServer