Closed rajeshwarpatlolla closed 5 years ago
I am using the same setup, but still not working. Don't be in a hurry to close the issue. Let's agree that, it's working first and then we can close it. If you close it, those who have some idea on it, will never look at this issue. Please re open this issue. Let me get some help from those who know the solution please.
I updated the examples. I tested each one of them today. They all work. I suggest you look at them and make sure they are working as-is first and once you get them to work, figure out your own problem.
And you are not using the same setup! For one, you are enabling ops but filtering them out with { log: '*', response: '*' }
. Try { log: '*', response: '*', ops: '*' }
instead.
I tried this as well.
I made few api calls, but i don't see any response on the console.
Then show the full code, because you're doing something wrong somewhere, and we can't help you with glimpses of partial code.
Here is the complete code of main file of the application
'use strict';
const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Vision = require('@hapi/vision');
const HapiSwagger = require('hapi-swagger');
const mongoose = require('mongoose');
const Config = require('./config');
const Routes = require('./routes');
const Pack = require('./package');
mongoose.connect(Config.database.uri, { useNewUrlParser: true, useCreateIndex: true });
let db = mongoose.connection;
db.on('connected', function callback() {
console.log('Connected to DB.');
init();
});
db.on('error', function() {
console.log('Connection to DB failed!');
process.exit(0);
});
db.on('disconnected', function(err) {
console.log('Connection teminated to DB ', err);
process.exit(0);
});
const init = async () => {
const server = Hapi.server({
host: Config.server.host,
port: Config.server.port,
routes: {
cors: true,
validate: {
// If any Joi validations fail, it will send the proper error message to the user
failAction: (request, h, err) => {
throw err;
},
},
},
});
const swaggerOptions = {
info: {
title: Config.swagger.title,
version: Pack.version,
contact: {
name: Config.swagger.contact,
},
},
schemes: ['http', 'https'],
securityDefinitions: {
jwt: {
type: 'apiKey',
name: 'Authorization',
in: 'header',
},
},
security: [{ jwt: [] }],
};
const goodOptions = {
ops: {
interval: 1000,
},
reporters: {
console: [
{
module: '@hapi/good-squeeze',
name: 'Squeeze',
args: [{ log: '*', response: '*', ops: '*' }],
},
{
module: '@hapi/good-console',
},
'stdout',
],
},
};
await server.register([
Inert,
Vision,
{
plugin: HapiSwagger,
options: swaggerOptions,
},
{
plugin: require('@hapi/good'),
goodOptions,
},
]);
try {
await server.start();
console.log(`Server running on ${server.info.uri}`);
console.log(`Swagger documentation is running on ${server.info.uri}/documentation`);
} catch (err) {
console.log(err);
}
server.route(Routes);
server.ext('onPostAuth', async (req, h) => {
return h.continue;
});
};
process.on('unhandledRejection', err => {
console.error(err);
process.exit(1);
});
I tried adding a static router as mentioned here, but still same issue. I don't see any logs.
Well, appears you didn't have the proper setup. If you rename goodOptions
to options
it will be a whole lot better.
Oh yea, sorry. I modified recently forgot to rename it. I made changes, but still i am getting no logs.
Well I do, so make sure you double checked everything.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
My setup is
When i run my server, server is starting and the apis are working fine. But i don't see any logs.
Any help would be really appreciated.