1.1.15 • Published 2 years ago

nghost v1.1.15

Weekly downloads
24
License
ISC
Repository
github
Last release
2 years ago

nghost

Install

$ npm i nghost

Description

Allows you to host web files such as the files generated by Angular from ng build --prod command.

Default content type

NameContent typeEncodage type
htmltext/htmltext
javascriptapplication/javascripttext
style sheettext/csstext
faviconimage/x-iconbinary
Javascript notationapplication/jsontext
Web Open Font Formatapplication/font-woff woffbinary
Web Open Font Format 2application/font-woff2binary
Embedded OpenTypeapplication/vnd.ms-fontobject eotbinary
True Typeapplication/octet-streambinary
Mapapplication/octet-streambinary
MPEG-4video/mp4binary
Adobe Flashvideo/x-flvbinary
Scalable Vector Graphicsimage/svg+xmlbinary
Jpgimage/jpgbinary
Jpegimage/jpegbinary
Pngimage/pngbinary

How to use

var nghost = require("nghost");

//Set Options

var options = {
  publicFolder: __dirname + "/dist",
  port: 8080,
  favicon: __dirname + "/dist/favicon.ico",
};

//Init Server

//nghost() function return Express application server.

var app = nghost(options);

//It's Done, Have a fun

Options

Here is all options params.

var  options = {
	publicFolder: path.join(__dirname, 'public'),
	hostname: 'localhost',
	favicon: path.join(__dirname, 'favicon.ico'),
	port: 80,
	https: false,
	key: path.join(__dirname, 'security', 'server.key'),
	cert: path.join(__dirname, 'security', 'server.crt'),
	ca: path.join(__dirname, "security", "chain.pem"),
	bodyParser: true,
	encode: 'utf-8',
	session: '',
	contents: [
		...
		//all content filter
		...
	],
	gets: [],
	posts: [],
	puts: [],
	deletes: [],
	"Access-Control-Allow-Origin": "*",
	"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept",
	simpleAuth: {
		enable: false,
		username: "",
		password: "",
		allowip: []
	},
	auth0: { //Auth0 login
		enable: false,
		AUTH0_DOMAIN: "",
		AUTH0_CLIENT_ID: "",
		AUTH0_CLIENT_SECRET: "",
		AUTH0_CALLBACK_URL: "",
	}
}

NgHost and Auth0

Default login system are append in project, "Auth0". For starting to use, change state of options.auth0.enable to true and complete your tenant information. If you not have, create an account on "Auth0.com"

Reserved route

  • (hostname):(port)/login
  • (hostname):(port)/logout

How it work

once logged user information stored in req.oidc.user, and auth status can check in req.oidc.isAuthenticated()

Simple Auth

Basic authorisation to acces on the web page.

...
simpleAuth: {
		enable: false,
		username: "",
		password: "",
		allowip: []
	},
...

Set enable to true and define username, password. if you want allow specific ip or network, add it in allowip array example:

	...
	allowip: [
		"192.168.1.1",
		"10.0.0.*"
	]
	...

in this example, ip 192.168.1.1 and all 10.0.0.* client can access without password.

Advance

To Add new requests, you must specify it in the Gets or Posts array in the options

//Example
//Traditionnal get and post
app.get("/foo", function(req, res){
	console.log("Your request is:", req.url);
	res.end();
})

app.post("/foo", function(req, res){
	console.log("your post var is:", req.body);
	res.end();
})

//nghost get and post
var options = {
....
	gets:[
		{
			key: "/foo",//regex
			function:  function (req, res) {
				console.log("Your request is:", req.url);
				res.end();
			}
		}
	],
	posts:[
		{
			key: "/foo",//regex
			function:  function (req, res) {
				console.log("your post var is:", req.body);
				res.end();
			}
		}
	]
....
}

Do not forget to add req and res arguments.

To Add new content-Type

var options = {
	....
	contents: [
		{
			key: /\.html$/,
			type:  'text',
			contentType:  'text/html'
		}
	]
	....
}

Place all web file in your specified public folder.

Change Log

######v. 1.0.2

  • debug: add body-parser for getting post value
//new options
var options = {
	....
	bodyParser: true, // True or False
	....
}

######v. 1.0.3

  • add: Session management
//new options
var options = {
	....
	session: 'SESSION_SECRET_KEY',
	....
}

######v. 1.0.5

  • debug: correction Post and Get Matching

######v. 1.0.10

  • debug: correction regex matching Post and Get in query

######v. 1.0.11

  • debug: correction binary content type

######v. 1.0.12

  • add: Access-Control-Allow-Origin headers params added

######v. 1.1.0

  • add: Auth0 authentification
  • debug: options merge
  • debug: binary content-type

######v. 1.1.7

  • add: Simple authentification

######v. 1.1.10

  • add: Https protocol Change https to true and set key and cert location

######v. 1.1.13

  • add: put,delete request

######v. 1.1.15

  • add: option ca for https credential
1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago