hapi-swagger disables my routes - javascript

Below is the glue manifest I use to fire up the server:
var Config = require('../config.json');
var internals = {
manifest: {
connections: [
{
host : Config.host || process.env.IP,
port : Config.apiPort || process.env.PORT,
labels : ['api']
}],
plugins: {
'./decorate': [{ 'select': ['api']}],
'hapi-auth-jwt': [{ 'select': ['api']}],
'./authentication': [{ 'select': ['api']}],
'./controllers': [{ 'select': ['api']}],
'./models': [{ 'select': ['api']}],
'./api': [{ 'select': ['api']}],
good: {
opsInterval: 5000,
reporters: [
{ 'reporter': 'good-console', 'events': { 'log': '*' } }
]
}
}
}
};
if (!process.env.PRODUCTION) {
internals.manifest.plugins['blipp'] = [{}];
internals.manifest.plugins['good'].reporters[0].events['ops'] = '*';
}
module.exports = internals.manifest;
As soon as I add 'hapi-swagger' to the list of plugins the server stops responding to the routes defined in the ./api file. None of the routes work. Is the the right way to add hapi-swagger to the glue manifest or am I doing something absurd?
EDIT: Below is the api.js
exports.register = function (plugin, options, next) {
plugin.dependency('controllers');
plugin.dependency('models');
var Controllers = plugin.plugins.controllers.handlers;
var Models = plugin.plugins.models.models;
plugin.bind({
models: Models
});
plugin.route([
{ method: 'GET', path: '/token', config: Controllers.Membership.token },
{ method: 'GET', path: '/', config: Controllers.Home.status },
{ method: 'GET', path: '/nodes', config: Controllers.Node.search },
{ method: 'GET', path: '/services', config: Controllers.Node.services },
{ method: 'GET', path: '/createnodetree', config: Controllers.Loader.createNodeTree }
]);
next();
};
exports.register.attributes = {
name: 'api',
version: require('../package.json').version
};

This happens if you try to use hapi-swagger without either including the documentation view dependencies or properly disabling documentation support. From the docs:
If you want to view the documentation from your API you will also need to install the inert and vision plugs-ins which support templates and static content serving. If you wish just to used swagger.json without the documentation for example with swagger-codegen simply set options.enableDocumentation to false.
You didn't show how you are adding the hapi-swagger plugin but you simply need to add 'enableDocumentation': false to options wherever you define that. You can find examples at the link above.

Related

Cypress 10 shows "The 'task' event has not been registered in the setupNodeEvents method. You must register it before using cy.task()"

In the cypress.config.js , I'm trying to register tasks / plug in events and set my env configuration exactly as documented on their guide.
However, when trying to use "on" inside setupNodeEvents I'm getting the error in the title about needing to register it.
Also, to note when passing both arguments (on, config), the config file does not pick up the env variable. Only when I put config first or config by itself, do the env variables pass.
Also, my tasks are properly coded inside the test classes. I know this because they work just fine for previous versions of cypress 9 but I can share them if someone thinks that's where the
/// <reference types="cypress" />
const { defineConfig } = require('cypress');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on,config) {
if (config.env == undefined) {
return {
baseUrl: "intentionally blank",
env: {
env: "test",
schedulerBaseUrl: "intentionally blank",
signInUrl: "intentionally blank",
enableAccessibility: true,
takeScreenShot: false,
suites: "",
},
};
}
else if (config.env == 'development') {
return {
baseUrl: "https://blank.blank.com:blank",
env: {
environment: "development",
schedulerBaseUrl: "intentionally blank",
signInUrl: "intentionally blank",
enableAccessibility: false,
takeScreenShot: false
},
}
}
on('task', {
log(message) {
console.log(message)
return null
},
table(message) {
console.table(message)
return null
}
})
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args.push('--disable-gpu');
launchOptions.args.push('--disable-dev-shm-usage');
launchOptions.args.push('use-fake-device-for-media-stream');
return launchOptions;
}
});
},
chromeWebSecurity: false,
screenshotOnRunFailure: false,
trashAssetsBeforeRuns: true,
numTestsKeptInMemory: 0,
video: true,
videoCompression: false,
enableAccessibility: false,
takeScreenShot: false,
defaultCommandTimeout: 10000,
execTimeout: 500000,
pageLoadTimeout: 500000,
retries: {
runMode: 1,
openMode: 0
},
blockHosts: [
"*intentionally blank"
],
redirectionLimit: 199,
projectId: "intentionally blank",
}
})
require('#applitools/eyes-cypress')(module);
I have had a similar issue, but for me it was the migration from Cypress 9.x.x to Cypress 10.+ while having some tasks and environmental variable overrides declared in the previous location, which was module.exports = (on, config) => {...} code block within ~/cypress/plugins/index.js file.
I tried migrating, yet I was running into some issues, yours included.
I came up with kind of a hacky way to keep it all in index.js and within cypress.config.js file I simply require the whole exported index.js module like this:
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
Hope this helps.

Cannot add response headers

This is the script I'm using:
const securityHeaders = [
{
key: 'X-XSS-Protection',
value: '1; mode=block'
},
{
key: 'Referrer-Policy',
value: 'origin-when-cross-origin'
}
]
module.exports = {
async headers() {
return [
{
// Apply these headers to all routes in your application.
source: '/:path*{/}?',
headers: securityHeaders,
},
]
},
}
But when I run npm run start and check the Response Headers for localhost, none of these headers appears.
Using next version 9.5.2
You can use source: "/(.*?)", or source: '/:path*',

Why Nuxt making multiple request for the "user" endpoint?

There is an Express server and a Nuxt client. Nuxt version is 2.15.7.
Entire auth configuration:
// nuxt.config.js
auth: {
plugins: [
{
src: '~/plugins/axios',
ssr: true
},
{
src: '~/plugins/auth'
}
],
cookie: {
prefix: 'auth.',
options: {
path: '/',
secure: process.env.NODE_ENV === 'production' ? true : false
}
},
localStorage: {
prefix: 'auth.'
},
vuex: {
namespace: 'auth'
},
strategies: {
local: {
scheme: 'refresh',
token: {
property: 'accessToken',
maxAge: 900,
global: true,
name: 'Authorization',
type: 'Bearer'
},
refreshToken: {
property: 'refreshToken',
data: 'refreshToken',
maxAge: 5184000
},
user: {
property: 'user',
autoFetch: false
},
endpoints: {
login: {
url: '/user/sign_in',
method: 'post'
},
logout: {
url: '/user/sign_out',
method: 'delete'
},
refresh: {
url: '/user/refresh',
method: 'get'
},
user: {
url: '/user/profile',
method: 'get'
}
}
}
},
redirect: {
login: '/auth/sign_in',
logout: '/',
callback: '/auth/sign_in',
home: '/'
}
}
When I refresh the page in the browser, I see this in the browser log:
This message comes from here:
// plugins/axios.ts
import { AxiosRequestConfig } from 'axios'
export default function ({ $axios, }: any) {
$axios.onRequest((config: AxiosRequestConfig) => {
console.log('Making request to ' + config.url)
})
}
There are also two requests in the server logs. But in the first request I can get, for example, cookies, and in the second one comes this:
// console.log(req.cookies)
[Object: null prototype] {}
Can you please tell me why there are two requests?
The problem was caused by the back end returning this after sign in:
{
"is": 1
}
And should return this:
{
"user": {
"is": 1
}
}
😬
After I added the "user" object, nuxt auth accepted the information and started working correctly.

Vue workbox, dont cache specific dynamic routes

How can I disable certain routes from getting cached by the service worker?
Eg I have a URL: https://someurl.com/emailValidate/1231231?email=some#email.com - The thing after emailValidate is a dynamic ID, which is why I dont want all things on the route /emailValidate and after that should not be cached by the SW...
I've tried adding this to the vue.config, but doesnt seem to do much:
module.exports = {
pwa: {
workboxPluginMode: 'InjectManifest',
workboxOptions: {
swSrc: './src/sw.js',
swDest: 'service-worker.js',
globIgnores: ['**/emailValidate', '**/passwordReset']
},
runtimeCaching: [
{
urlPattern: new RegExp('/emailValidate'),
handler: 'NetworkFirst'
},
{
urlPattern: new RegExp('/passwordReset'),
handler: 'NetworkFirst'
}
],
navigateFallbackBlacklist: ['/emailValidate', '/passwordReset']
}
};

hello.js: Is it possible to set the provider's settings dynamically?

I have implemented a new module for hello.js.
I need the auth, grant and base to be dynamic.
Is there a way to set/override these values from the hello.init() call?
My module looks like this:
(function(hello) {
hello.init({
my_service_name: {
name: 'My-Service-Name',
oauth: {
version: 2,
auth: 'http://mydomain/oauth/authorize',
grant: 'http://mydomain/oauth/token'
},
scope: {
basic: ['basic_scope']
},
base: 'http://mydomain/',
xhr: function(p) {
if (p.method !== 'get' && p.data) {
// Serialize payload as JSON
p.headers = p.headers || {};
p.headers['Content-Type'] = 'application/json';
if (typeof (p.data) === 'object') {
p.data = JSON.stringify(p.data);
}
}
return true;
}
}
});
})(hello);
and my hello.init() call:
hello.init({
my_service_name: server.consumerKey
}, {
redirect_uri : server.callbackUrl,
});
The use-case is that the application I am developing will communicate with several servers, so I cannot hardcode the URLs in the module's file.
I figured out that I can override the default settings by passing the whole oauth object in the hello.init() call:
hello.init({
my_service_name: {
id: server.consumerKey,
oauth: {
version: 2,
auth: server.auth_url,
grant: server.token_url
},
base: server.baseUrl
}
}, {
redirect_uri : server.callbackUrl
});

Categories

Resources