Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Gosling is simple, plugin ready es6 node server similar to express.
import Gosling from 'gosling';
const app = new Gosling(1337);
app.listen();
app.use('/', () => (request, response, next) => {
response.write('Hello World!');
next();
});
HTTPS can be used out of the box with Gosling. Pass a node https options object to the constructor.
Note: HTTPS Options should either be the first or second argument, if second we assume Port is the first.
import { readFileSync } from 'fs';
import Gosling from 'gosling';
const httpsOptions = {
key: readFileSync('./ssl/key.pem'),
cert: readFileSync('./ssl/cert.pem')
};
const app = new Gosling(1337, httpsOptions);
app.listen();
Gosling ships with a router bundled, it can be accessed by importing separately
import Gosling, { Router } from 'gosling';
const app = new Gosling(1337);
const router = new Router();
app.listen();
router.use('/', () => (req, res, next) => {});
app.use('/api', router);
When assigning a path to router that router is then scoped to only process request that match the prefix.
Routers are completely recursive and can be nested deeply.
import { Router } from 'gosling';
const router = new Router();
const subrouter = new Router();
subrouter.get(/\/post\/[a-z0-9]+$/, bobsLawBlog);
router.use('/api/blog', subrouter);
export router;
Gosling's constructor takes the following optional arguments:
Once instantiated Gosling offers the following methods:
listen
Number
) - throws error if port is already assignedFunction
)close
Function
)port
use
(Universal request)
String
or RegExp
get
String
or RegExp
post
String
or RegExp
put
String
or RegExp
delete
String
or RegExp
The methods
(get
, post
, put
, delete
, use
) API takes two arguments and creates Request Objects…
- Path (as String or RegExp) [optional]
- Thunk (function returning function) [required]
- Note: All method calls are chainable app.use().get().post()
is valid.
Request Objects are the heart of Gosling's speed and simplicity. They can be hand coded or passed through the method
API reducer.
// Request Object
{
path: '/' /* String or RegExp */
method: /GET/i /* RegExp only */
thunk() {
/* some code */
return (request, response, next) => {
/* response or request modifications */
next();
}
}
}
You can use the simple API to produce Request Objects by:
app.use('<Path>', () => (req, res, next) => {});
app.get('<Path>', () => (req, res, next) => {});
app.post('<Path>', () => (req, res, next) => {});
app.put('<Path>', () => (req, res, next) => {});
app.delete('<Path>', () => (req, res, next) => {});
methods
API does the work of Method checking, so no need to pass that.use
method will try to run on every request.path
is passed in, the thunk is processed on all matching request methods.
app.use(() => (req, res, next) => {})
will be run on all requests.method
calls are chainable
app.use(() => {}).get(() => {}).post(() => {});
FAQs
Gosling is a simple es6 node server, similar to express.
We found that gosling demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.