Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xeaone/nety
https://github.com/xeaone/nety
async server single-page-app spa static
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/xeaone/nety
- Owner: xeaone
- License: mpl-2.0
- Created: 2017-04-27T22:16:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-07-12T22:59:51.000Z (over 3 years ago)
- Last Synced: 2024-11-08T11:09:19.595Z (6 days ago)
- Topics: async, server, single-page-app, spa, static
- Language: JavaScript
- Homepage:
- Size: 18.3 MB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
[![Total alerts](https://img.shields.io/lgtm/alerts/g/vokeio/nety.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/vokeio/nety/alerts/)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/vokeio/nety.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/vokeio/nety/context:javascript)# Nety
Server module for building API, SPA, and WEB applications. Zero dependencies.## Overview
Single page application mode all request will check to see if the requested path exists on the file system.
Otherwise it will serve the default file `index.html`. See the test directory for more advanced examples.## Features
- async/await
- static files server
- built in auth handling
- no external dependencies
- spa/single page application
- redirects all urls with out extensions and wih .html to the root file## Install
`npm i nety --save`## Example
```js
const Nety = require('../src');
const { Controller, HttpServer } = Nety;
const { Server, Basic, Cache, Cookie, File, Payload, Normalize, Preflight, Session } = HttpServer;const validate = async (context, username, password) => {
if (username !== 't' || password !== 't') {
return { valid: false };
} else {
return { valid: true };
}
};const file = new File();
const cache = new Cache();
const cookie = new Cookie();
const payload = new Payload();
const normalize = new Normalize();
const preflight = new Preflight();
const basic = new Basic({ validate, secret });const server = new Server({
port: 8080,
// version: 2, http2 experimental
debug: true,
host: 'localhost'
});await server.add(normalize);
await server.add(preflight);
await server.add(cache);
await server.add(cookie);
await server.add(payload);
await server.add(basic);
await server.add(file);await server.get('/', async context => {
context.type('html').body(`Hello World
`).end();
});await server.get(async context => {
return context.file({
spa: true,
folder: './static',
path: context.url.pathname
});
});await server.open();
console.log(`Host: ${server.host}, Address: ${server.address}, Port: ${server.port}`)
```## Authors
[Alexander Elias](https://github.com/vokeio)## License
[Why You Should Choose MPL-2.0](http://veldstra.org/2016/12/09/you-should-choose-mpl2-for-your-opensource-project.html)
This project is licensed under the MPL-2.0 License