9.7.0 • Published 6 years ago

hops-server v9.7.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

Hops Server

deprecated

This package is deprecated. Please use hops-express instead.

npm

Hops server is a small collection of shared functionality that can be used in express-like interfaces to register the hops-middleware.

It also exports a simple middleware that takes care of rewriting the paths of incoming http requests based on the values set in hops-config.

Exports:

  • rewritePath(request, response, next) => void\ rewritePath is an express-style middleware that adds a trailing slash to the url of the incoming request.

  • registerMiddleware(app, middleware) => void\ registerMiddleware is a helper function that registers a wildcard middleware for every location defined in the hops-config, if available. Otherwise it registers the given middleware for a wildcard route at the root.

  • run(app, callback) => void\ run is a helper function that starts the express-like server with the parameters defined in hops-config.

  • bootstrap(app, hopsConfig) => void\ teardown(app, hopsConfig) => void These functions allow to customize the server through hops-config. It is possible to define hopsConfig.bootstrapServer and hopsConfig.teardownServerto override these functions and execute some custom logic on the app object.

Target Audience

If you want to build an express-like server and reuse the hops-config while doing so, then this middleware will help dealing with the locations and basePath config.

Example

app.js

var path = require('path');
var express = require('express');
var server = require('hops-server');
var hopsConfig = require('hops-config');

// middleware generated by hops-build, based on the webpack node config
var pathToGeneratedMiddleware = path.join(hopsConfig.cacheDir, 'server.js');

// generic Express server application
var app = express();
app.use(server.rewritePath);

// bootstrap and teardown provide hooks to customize the server through hops-config
server.bootstrap(app, hopsConfig);
server.registerMiddleware(require(pathToGeneratedMiddleware));
server.teardown(app, hopsConfig);

// actually run application
server.run(app);
9.7.0

6 years ago

9.6.0

6 years ago

9.5.0

6 years ago

9.3.0

6 years ago

9.1.1

6 years ago

9.0.1

6 years ago

8.0.0

6 years ago

7.2.0

7 years ago

7.1.0

7 years ago

7.0.0

7 years ago

7.0.0-3

7 years ago

7.0.0-0

7 years ago

6.0.0-beta.17

7 years ago

6.0.0-beta.16

7 years ago

6.0.0-beta.15

7 years ago

6.0.0-beta.14

7 years ago

6.0.0-beta.13

7 years ago

6.0.0-beta.12

7 years ago

6.0.0-beta.11

7 years ago

6.0.0-beta.10

7 years ago

6.0.0-beta.9

7 years ago

6.0.0-beta.8

7 years ago

6.0.0-beta.7

7 years ago