JHipster custom component GET http://localhost:9000/api/account 401 (Unauthorized) - jhipster

I have created JHipster monolithic application.
Using jdl-studio i have created entities.
After that i have created my own module with submodules.
In app.module.ts i have created app-routing.module.ts
#NgModule({
imports: [RouterModule.forRoot(routes, config)],
exports: [RouterModule],
})
in app-routing module routing to other modules is defined like this
const routes: Routes = [
{
path: 'dashboard', loadChildren: () => new Promise(resolve => {
(require as any).ensure([], require => {
resolve(require('./pages/pages.module').PagesModule);
})
})
},
{
path: '',
redirectTo: '/dashboard',
pathMatch: 'full'
},
{path: '**', redirectTo: 'pages'},
Routing works just fine, i have no problems at all.
But when i try calling entities services from custom components which are defined inside this custom modules, i receive error
GET http://localhost:9000/api/account 401 (Unauthorized)
I am able to login without problems, i am able to access Principal service inside header, but when i try calling any of services from inside custom components i receive this error
What could be the problem?
Thanks in advance

Related

Can't find path when build project in vue3

When I build the project and run it, The first page can run properly and the redirect is working but when I change the path it show Can't get /admin(path name) it's seems like I can't direct by typing the URL.
It's work fine when I run serve.
Here is my router index.js
import Blog from "../views/Blog.vue";
import Admin from "../views/Admin.vue";
const routes = [
{ path: "/", redirect: "/blog" },
{ path: "/blog",name: "blog",component: Blog },
{ path: "/admin", name: "admin", component: Admin },
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL), routes,
});
export default router;

Jest+NextJs: You should only use "next/router" on the client side of your app

I'm mocking the next/router dependency in my Jest+React-testing-libray tests as I always have:
import * as nextRouter from 'next/router';
export const routerData = {
pathname: '/users/create',
route: '/users/create',
query: { },
asPath: '/users/create',
isFallback: false,
basePath: '',
isReady: true,
isPreview: false,
isLocaleDomain: false,
events: {},
};
// mock router
jest.mock('next/router');
nextRouter.useRouter.mockImplementation(() => (routerData));
describe('a component that requires next/router, () => ... );
This had been working correctly but after updating to NextJs 12.2.0 I get this warning:
No router instance found.
You should only use "next/router" on the client side of your app.
This warning makes all my tests with the mocked router to fail.
Ideas to fix this?
Well, it appears that this is not related to 12.2.0. Somehow my last version of Next - 12.0.0 - wasn't thrownig this error but other older versions did.
Thanks to bistacos for the response here.
const useRouter = jest.spyOn(require('next/router'), 'useRouter');
useRouter.mockImplementation(() => ({
pathname: '/',
...moreRouterData
}));

How to use NestJS Versioning with Router module

In our nest 8 project we use the RouterModule for routing between different parts of the app:
#Module({
imports: [
RouterModule.register([
{
path: '/internal',
module: InternalModule
},
{
path: '/external',
module: ExternalModule
}
]),
],
})
export class AppModule {}
In the InternalModule we would like to use NestJS versioning:
#Controller('someroute')
export class InternalController {
#Get(':id')
#Version(['1'])
async getPerson(#Param('id') id): Promise<any> {}
}
Routing without versioning works, versioning without routing too, but the combination does not.
I tried calling it via "localhost:port/v1/internal/someroute" and "localhost:port/internal/v1/someroute"
Versioning is enabled:
app.enableVersioning({
type: VersioningType.URI
});

NextJS and KeystoneJS website cant get GraphQL data (Error: No executable schema named 'public' is available)

I am currently making a NextJS website with KeystoneJS as the CMS. I can't find any good guides on how to set this up correctly so I have just jumped in. An issue that I am currently experiencing is that I am unable to request data from GraphQL. I can do it through the playground, just not the nextjs pages.
I have tried the following methods:
Axios => Module not found: Can't resolve 'async_hooks'
fetchAPI => Module not found: Can't resolve 'async_hooks'
getItems => Error: No executable schema named 'public' is available. Have you setup '#keystonejs/app-graphql'?
I am pretty sure that I should be using getItems since it is imported from #/keystonejs/server-side-graphql-client. However I'm not sure if I have set it up correctly.
My current project setup is installing KeystoneJS - Blank template. and then I have manually installed NextJS based on the installation guide. My module exports looks like this:
module.exports = {
keystone,
apps: [
new GraphQLApp(),
new AdminUIApp({
name: PROJECT_NAME,
enableDefaultRoute: false,
authStrategy,
isAccessAllowed: isAdmin,
})
],
};
Here is my getItems request:
export async function getStaticProps() {
const posts = await getItems({
keystone,
listKey: 'Post',
returnFields: 'name'
});
console.log(posts);
return {
props: {
posts,
},
}
};

Vue Website Returns "Cannot Get /path" On All Pages EXCEPT Index

I am using Vue on Node.js to host my website on an AWS EC2 instance. I dont have an index node.js file, just the vue-router file. I use AWS CloudFront to bind my certificate to my traffic. The problem is that everytime i access the site through the server's link, the site works perfectly, but whenever i access it through the cloud-front link, only the index of the website will show up. No /about or /contact; instead it returns Cannot GET /about.
My Router:
import Vue from 'vue';
import Router from 'vue-router';
import VueCookies from 'vue-cookies';
import Home from './views/Home.vue';
import NotFound from './views/NotFound.vue';
Vue.use(Router);
Vue.use(VueCookies);
VueCookies.config('7d');
VueCookies.set('theme', 'default');
VueCookies.set('unique', Date.now());
VueCookies.set('rwapi-uuid', `v3-${Date.now()}-x9k0`)
export default new Router({
mode: 'history',
routes: [
{ path: '/', name: 'INDEX', component: Home },
{ path: '/about/', name: 'ABOUT', component() { return import('./views/About.vue'); } },
{ path: '/portfolio', name: 'PORTFOLIO', component() { return import('./views/Port.vue'); } },
{ path: '/contact', name: 'CONTACT', component() { return import('./views/Contact.vue'); } },
{ path: '/login', name: 'LOGIN', component() { return import('./views/Login.vue'); } },
{ path: '/404', component: NotFound },
{ path: '*', redirect: '/404' },
],
});
I have already tried to add the historyApiFallback: true to my webpack config but it had no effect.
According to Vue Router's documentation, when using your router in history mode, your webserver requires additional configuration.
I don't exactly know how do EC2 instances work, but if you don't have a webserver proxying all your requests to index.html, Vue-router will not be able to handle the other requests.

Resources