franciscop / server

:desktop_computer: Simple and powerful server for Node.js
https://serverjs.io/
MIT License
3.56k stars 171 forks source link

How to use morgan on server? #113

Closed LucasMonteiro1 closed 5 years ago

LucasMonteiro1 commented 5 years ago

I tried

server(options, routes).then((ctx) => {
  ctx.app.use(morgan('tiny'));
});

and

server(options, routes, morgan);

and

server(options, routes, morgan('tiny'));

After installing the morgan dependency, I changed the file server/plugins/express/index.js, after the line ctx.app = ctx.express(); added ctx.app.use(morgan('tiny')); and it worked.

franciscop commented 5 years ago

Have a look at Express Middleware, have you tried something like this?

const server = require('server');

// Convert an Express to a Server middleware
const morgan = server.utils.modern(require('morgan')({ ... }));

// Add it as you'd add a normal middleware
server({}, morgan, ...);
LucasMonteiro1 commented 5 years ago

It worked using the middleware. Thank you for your help!!

franciscop commented 5 years ago

Happy to help :)