@wfh/express-app
TypeScript icon, indicating that this package has built-in type declarations

1.1.11 • Public • Published

Express server

This package contains Express web framework as core package. Also this package is API provider.

Supported Express middlewares

You don't need to add following middleware, they have already been onboard.

  • cookie-parser

  • body-parser

  • compression

new API

New Node API methods

Name description
.router() return an Express Router object
.use() Express use() method, to bind middleware
.param() Express param() method
.expressAppSet(callback) callback: function(app, express), whatever things you want to do before express's app getting initialized
.swig express view engines: require('swig-template')
.express express instance, so that you can access some express middleware, like api.express.static
.expressApp the main express app instance used by us, which is value of express()
.cors() CORS middleware for specific route path, e.g. api.router().use('/api', api.cors());
check setupApi.js

Above API methods must be called within module.exports.activate() function e.g.

var api = require('__api');

exports.activate = function() {
	api.router().get(function(req, res) {
		res.render('/template.html');
	});
};

e.g. expressAppSet(callback)

exports.activate = function(){
 	api.expressAppSet((app, express) => {
 		app.set('trust proxy', true);
		app.set('views', Path.resolve(__dirname, 'web/views/'));
	});
};

Check server side git hash

You need put generate a git hash text file in root folder like,

git rev-parse HEAD > githash-server.txt
echo \"I am in Dev\" >> githash-server.txt

Or put in your package.json npm script:

"scripts": {
	"build": "git rev-parse HEAD > githash-server.txt && echo \"I am in Dev\" >> githash-server.txt:
}

Once your start server by node app, you can access /githash-server or /githash-server.txt

Readme

Keywords

none

Package Sidebar

Install

npm i @wfh/express-app

Weekly Downloads

0

Version

1.1.11

License

none

Unpacked Size

59.7 kB

Total Files

18

Last publish

Collaborators

  • liujingbreak