Open murilo-campaner opened 6 years ago
Hi @murilo-campaner, not sure if this is a rest-hapi specific issue, but I remember running into something similar earlier that was related to hapi-swagger. Updating to the latest version of hapi-swagger fixed the issue. If you use rest-hapi v0.27.3 and higher it uses an updated version of hapi-swagger that might help.
Hello @JKHeadley! Thank you for your response!
I updated to rest-hapi v0.27.3 and now is all right, problem resolved! But... I got one another problem...
My server is running with nginx, and my api server is redirecting all HTTP requests to HTTPS. But, when I use swagger-ui to send requests, it give no response back and if I inspect in console, the requests is going by HTTP, not HTTPS.
And here's my API code:
'use strict';
const Hapi = require('hapi');
const mongoose = require('mongoose');
const restHapi = require('rest-hapi');
const env = require('dotenv').config().parsed;
function api(){
const hapiConfig = {
server: 'https://api.youchoose.com.br',
appTitle: "YouChoose API",
enableTextSearch: true,
docExpansion: "list",
mongo: {
URI: `mongodb://${env.DB_USER}:${env.DB_PASSWORD}@${env.DB_HOST}:${env.DB_PORT}/${env.DB_DATABASE}`
}
};
restHapi.config = hapiConfig;
const server = new Hapi.Server();
server.connection({
port : env.API_PORT,
routes: {
cors: {
origin: ['*'],
additionalHeaders: ['origin']
}
}
});
server.register({
register: restHapi,
options: {
mongoose: mongoose,
}
},
function () {
server.start();
});
return server;
}
module.exports = api();
(If i use postman to send request using HTTPs, it works!)
I can open another issue if you want ok?
Thank you again!
@murilo-campaner not sure what's going on here, but I have a project using HTTPS with functioning swagger, so I do know it can work. I'll try looking into it and see if I can find anything.
Also, I would suggest posting your issue on the hapi-swagger page as well, since this seems to be centered on that plugin.
@JKHeadley Do you have a project that uses Nginx proxy to redirect request on a path to your rest-hapi project port.
In my case, https://host/services
proxys requests to https://host:8080
. In this case, everything works as expected apart from the swagger doc, all the swagger statics are fetched from host/...
and hence are 404
.
Really not sure if it's a proxy issue or has something to do with the setup.
@rahil471 I have not set up a project directly using Nginx, however, the project I mentioned above uses Cloudflare to redirect to rest-hapi, and I believe they use Nginx for reverse-proxying.
I will continue to look into this issue, but for now I suggest posting the issue on the hapi-swagger page or browsing their issues.
Hello everybody.
I'm trying to duplicate my actual production environment to create dev environment in same server. I already duplicate database and nginx configuration for another domain, but, when I access my dev environment I got the following error:
Debug: internal, implementation, error TypeError: Uncaught error: Converting circular structure to JSON at Object.stringify (native) at Object.internals.paths.build.internals.paths.buildRoutes.internals.hasFileType (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi-swagger/lib/paths.js:381:28) at /var/www/dev-api.mydomain.com.br/public/node_modules/hapi-swagger/lib/paths.js:223:23 at Array.forEach (native) at internals.paths.build.internals.paths.buildRoutes.routes [as buildRoutes] (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi-swagger/lib/paths.js:179:12) at internals.paths.build.routes.forEach [as build] (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi-swagger/lib/paths.js:151:17) at Object.builder.getSwaggerJSON (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi-swagger/lib/builder.js:110:26) at settings.log.plugin.route.config.handler.plugin.methods.getSwaggerJSON.Builder.getSwaggerJSON (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi-swagger/lib/index.js:115:29) at Object.exports.execute.internals.prerequisites.internals.handler.finalize [as handler] (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi/lib/handler.js:101:51) at /var/www/dev-api.mydomain.com.br/public/node_modules/hapi/lib/handler.js:32:23 at internals.Protect.run.finish [as run] (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi/lib/protect.js:60:12) at exports.execute.finalize (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi/lib/handler.js:26:22) at each (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi/lib/request.js:401:16) at iterate (/var/www/dev-api.mydomain.com.br/public/node_modules/items/lib/index.js:36:13) at done (/var/www/dev-api.mydomain.com.br/public/node_modules/items/lib/index.js:28:25) at module.exports.internals.state.next (/var/www/dev-api.mydomain.com.br/public/node_modules/hapi/lib/route.js:292:16)
My production environment is working. Anyone can help-me with this?
(I have replaced the url of my domain to dev-api.mydomain.com.br for obvious reasons)
Thanks :)