https://github.com/gfilho/base-server
A lightweight wrapper for Express that allows easily setup HTTP headers and SSL.
https://github.com/gfilho/base-server
api app expres http-header https javascript rest restful router ssl
Last synced: 10 months ago
JSON representation
A lightweight wrapper for Express that allows easily setup HTTP headers and SSL.
- Host: GitHub
- URL: https://github.com/gfilho/base-server
- Owner: gfilho
- License: mit
- Created: 2019-04-21T20:14:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-15T04:11:07.000Z (over 6 years ago)
- Last Synced: 2025-03-04T20:38:09.235Z (10 months ago)
- Topics: api, app, expres, http-header, https, javascript, rest, restful, router, ssl
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @gfilho/base-server
A lightweight wrapper for Express that allows easily setup HTTP headers and SSL.
[](https://app.codacy.com/app/gfilho/base-server?utm_source=github.com&utm_medium=referral&utm_content=gfilho/base-server&utm_campaign=Badge_Grade_Dashboard)
[](https://travis-ci.com/gfilho/base-server)
[](https://codecov.io/gh/gfilho/base-server)
## Getting Started
### Installation
```bashp
npm install @gfilho/base-server --save
```
### Simple Server
This is example show how create a simple REST server using the @gfilho/base-server:
``` js
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:
``` js
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](LICENSE)