Skip to content

A lightweight wrapper for Express that allows easily setup HTTP headers and SSL.

License

Notifications You must be signed in to change notification settings

gfilho/base-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@gfilho/base-server

A lightweight wrapper for Express that allows easily setup HTTP headers and SSL.

Codacy Badge Build Status codecov

Getting Started

Installation

npm install @gfilho/base-server --save

Simple Server

This is example show how create a simple REST server using the @gfilho/base-server:

var Server = require('@gfilho/base-server');

// Setup Server
const config = {
  router: {
    address: 'api',
    port: 1234,
  },
};

// Instance of Server
const server = new Server(config);

// Bind requests
server.get('/ping', (req, res) => {
  res.json({ msg: 'Ops! I received a GET' });
});

// Run Server
server.start();

Complete Server

This is example show a REST server using all features allowed by @gfilho/base-server:

var Server = require('@gfilho/base-server');

// Setup Server
const config = {
  router: {
    address: 'api',
    port: 1234,
    header: {
      allowedMethods: 'GET PUT POST DEL',
      allowedHost: 'mydomain.com',
      allowedHeaders: 'MySpecialHeader',
      allowedCredentials: true,
    },
    ssl: {
      key: 'examples/ssl/key.pem',
      certificate: 'examples/ssl/server.crt',
    },
  },
};

// Instance of Server
const server = new Server(config);

// Bind requests
server.get('/ping', (req, res) => {
  res.json({ msg: 'Server https is alive' });
});

server.put('/ping', (req, res) => {
  res.json({ msg: 'Ops! I received a PUT' });
});

server.post('/ping', (req, res) => {
  res.json({ msg: 'Ops! I received a POST' });
});

server.delete('/ping', (req, res) => {
  res.json({ msg: 'Ops! I received a DEL' });
});

// Run Server
server.start();

License

MIT

About

A lightweight wrapper for Express that allows easily setup HTTP headers and SSL.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published