I am not able to create a sitemap for my Gatsy site.
I have multi domains and work with Gatsby 2, but since I move for Gatby 4 my sitemap is like this :
<loc>https://inte.****.fr/https://inte.****.it/intimo-premaman</loc>
But i need only .it for work for this exemple.
I try this pluging when I follow the doc of Gatsby gatsby-plugin-complex-sitemap-tree,
But I realize it's a same problem. They work only with 1 domain.
My gatsby-config :
resolve: `gatsby-plugin-complex-sitemap-tree`,
options: {
query: `
{
allTaxonIt {
edges {
node {
id
slug
}
}
}
allTaxonFr {
edges {
node {
id
slug
}
}
}
allTaxonDe {
edges {
node {
id
slug
}
}
}
allTaxonGb {
edges {
node {
id
slug
}
}
}
allTaxonUs {
edges {
node {
id
slug
}
}
}
allTaxonEs {
edges {
node {
id
slug
}
}
}
allProductDe {
edges {
node {
id
slug
}
}
}
allProductGb {
edges {
node {
id
slug
}
}
}
allProductUs {
edges {
node {
id
slug
}
}
}
allProductEs {
edges {
node {
id
slug
}
}
}
allProductFr {
edges {
node {
id
slug
}
}
}
allProductIt {
edges {
node {
id
slug
}
}
}
allPageDe {
edges {
node {
id
slug
}
}
}
allPageGb {
edges {
node {
id
slug
}
}
}
allPageUs {
edges {
node {
id
slug
}
}
}
allPageEs {
edges {
node {
id
slug
}
}
}
allPageFr {
edges {
node {
id
slug
}
}
}
allPageIt {
edges {
node {
id
slug
}
}
}
}`,
sitemapTree: {
fileName: 'sitemap.xml',
loc: null,
serializer: (edge) => {
return {
loc: `${process.env.GATSBY_SITE_URL_IT}${edge.slug}`,
loc2: `${process.env.GATSBY_SITE_URL}${edge.slug}`,
slug: edge.slug,
lastmod: buildDate,
}},
children: [
{
fileName: 'sitemap-taxon-it.xml',
queryName: 'allTaxonIt',
},
{
fileName: 'sitemap-taxon-fr.xml',
queryName: 'allTaxonFr',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_FR}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-taxon-de.xml',
queryName: 'allTaxonDe',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_DE}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-taxon-gb.xml',
queryName: 'allTaxonGb',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_GB}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-taxon-us.xml',
queryName: 'allTaxonUs',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_US}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-taxon-es.xml',
queryName: 'allTaxonEs',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_ES}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-product-it.xml',
queryName: 'allProductIt',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_IT}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-product-fr.xml',
queryName: 'allProductFr',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_FR}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-product-de.xml',
queryName: 'allProductDe',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_DE}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-product-gb.xml',
queryName: 'allProductGb',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_GB}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-product-us.xml',
queryName: 'allProductUs',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_US}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-product-es.xml',
queryName: 'allProductEs',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_ES}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-page-it.xml',
queryName: 'allPageIt',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_IT}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-page-fr.xml',
queryName: 'allPageFr',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_FR}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-page-de.xml',
queryName: 'allPageDe',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_DE}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-page-gb.xml',
queryName: 'allPageGb',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_GB}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-page-us.xml',
queryName: 'allPageUs',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_US}${edge.slug}`, lastmod: buildDate }),
},
{
fileName: 'sitemap-page-es.xml',
queryName: 'allPageEs',
serializer: (edge) => ({ loc: `${process.env.GATSBY_SITE_URL_ES}${edge.slug}`, lastmod: buildDate }),
},
],
},````
Related
Hello guys can you help me please!
My app use up to 100% CPU when a lot of users go to my app.
I tried a lot of things, and my config turned into a mess
This is my nuxt.config.ts.
import type { NuxtConfig } from '#nuxt/types';
const isDev = process.env.NODE_ENV !== 'production';
const mainConfig: NuxtConfig = {
...
build: {
cache: true,
optimization: {
minimize: true,
runtimeChunk: true,
concatenateModules: true,
splitChunks: {
chunks: 'all',
minSize: 30000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 20,
maxInitialRequests: 3,
automaticNameDelimiter: '~',
name: true,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
chunks: 'all'
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
},
filenames: {
app: ({ isDev }) => (isDev ? '[name].js' : 'js/[name]/[contenthash].js'),
chunk: ({ isDev }) => (isDev ? '[name].js' : 'js/[name]/[contenthash].js'),
css: ({ isDev }) => (isDev ? '[name].css' : 'css/[contenthash].css'),
img: ({ isDev }) => (isDev ? '[path][name].[ext]' : 'img/[contenthash:7].[ext]'),
font: ({ isDev }) => (isDev ? '[path][name].[ext]' : 'fonts/[contenthash:7].[ext]')
},
extend(config, { isClient }) {
config.externals = [
function (context, request, callback) {
if (/(pdfmake)/.test(request) || /(xlsx)/.test(request)) {
return callback(null, 'commonjs ' + request);
}
callback();
}
];
}
},
router: { ... },
modules: [ ... ],
server: { ... },
watchers: {
webpack: {
ignored: ['**/node_modules', 'node_modules']
}
}
};
export default mainConfig;
The application does not stand up to 2000 users and breaks,
I really dont know what to do! :(
Maybe you will can help me?
I have got a few sql tables as
export default (sequelize, Sequelize) => {
return sequelize.define('teacher', {
tagline: {
type: Sequelize.TEXT,
},
modeOfPayment: {
type: Sequelize.STRING,
},
modeOfSession: {
type: Sequelize.STRING,
},
preferredTimeZones: {
type: Sequelize.STRING,
},
titleForSessions: {
type: Sequelize.STRING,
},
availableForWork: {
type: Sequelize.BOOLEAN,
},
});
};
export default (sequelize, Sequelize) => {
return sequelize.define('skill', {
name: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
});
};
export default (sequelize, Sequelize) => {
return sequelize.define('category', {
name: {
type: Sequelize.STRING,
unique: true,
allowNull: false,
},
});
};
Here is the model relation between them
Teacher.belongsToMany(Skill, {
through: 'skill_teacher',
});
Skill.belongsToMany(Teacher, {
through: 'skill_teacher',
});
Category.hasMany(Skill);
Skill.belongsTo(Category);
Earlier I needed to query count of teachers in each skill, here's my controller for that
// #desc Get skill count for each skill
// #route GET /api/skills/count
// #access Public
const getSkillCount = asyncHandler(async (req, res) => {
try {
const skills = await Skill.findAll({
attributes: [
'id',
'name',
[sequelize.fn('count', sequelize.col('teachers.id')), 'teacherCount'],
],
include: [{ attributes: [], model: Teacher }],
group: ['skill.id'],
});
res.json(skills);
} catch (err) {
console.log(err.message);
res.status(500);
throw new Error(err.message);
}
});
Now, the skills are grouped in categories. So I wanna query a list of skills having their own teacher count grouped in their own categories, which category also having a skillCount column. I tried this but it is not giving my desired results
// #desc Get category and their skills counts
// #route GET /api/categories/skills/count
// #access Public
const getCategorySkillCounts = asyncHandler(async (req, res) => {
try {
const categories = await Category.findAll({
attributes: [
'id',
'name',
[sequelize.fn('count', sequelize.col('skills.id')), 'skillCount'],
],
include: {
model: Skill,
include: [{ model: Teacher }],
attributes: [
'id',
'name',
[sequelize.fn('count', sequelize.col('teachers.id')), 'teacherCount'],
],
group: ['skill.id'],
},
group: ['category.id'],
});
res.json(categories);
} catch (err) {
console.log(err.message);
res.status(500);
throw new Error(err.message);
}
});
I am using vuex and vue-router. I have a client's zone, when you try to loggin, you should go to the profil. But it's not happend.
routes: [
{
path: "/area-do-cliente",
name: "customerZone",
redirect: "/area-do-cliente/profile",
component: () =>
import(
/* webpackChunkName: "ClientZone" */ "#/scenes/ClientZone/views/ClientZone.vue"
),
children: [
{
path: "login",
name: "login",
component: () => import("#/scenes/ClientZone/components/LogIn.vue"),
props: true,
meta: { clientZoneLogin: true }
},
{
path: "profile",
name: "profile",
component: () => import("#/scenes/ClientZone/components/Profile.vue"),
meta: { clientZoneAuthRequired: true, clientZoneLogin: true },
props: true
},
]
}
]
router.beforeEach((to, from, next) => {
if (to.matched.some(_to => _to.meta.clientZoneLogin))
if (store.getters.personData.status == "1") {
console.log("01");
router({ name: "profile" });
} else {
console.log("2");
next();
}
} else {
console.log("3");
next();
}
}
});
So I still have in console => 2. It is mean that I pass the first condition, but I shouldnt. I have status 1, and the response of this data is when you click the login button (there is a event).
methods: {
doLogin: function() {
this.error = "";
let loginData = {
login: this.login,
password: this.password
};
this.isLoading = true;
this.errorMessage = "";
co.postLogin(loginData)
.then(data => {
this.$store.commit("personData", data.data); // here I push data to store
)}
}
}
Any ideas where is mistake?
I have been implementing an authorization step which I modeled on THIS question's answer by fragsalat.
Everything works until it reaches the line
return new Redirect('login');
upon which I get the error:
aurelia-logging-console.js:47 ERROR [app-router] Error: Expected router pipeline to return a navigation result, but got [{"url":"login","options":{"trigger":true,"replace":true},"shouldContinueProcessing":false}] instead.
at processResult (aurelia-router.js:1761)
at aurelia-router.js:1725
at <anonymous>
I am not sure why this has not just redirected?
This is the full app.ts file so you might see the context:
import { Aurelia, PLATFORM, autoinject } from "aurelia-framework";
import {
Redirect,
NavigationInstruction,
Router,
RouterConfiguration,
Next
} from "aurelia-router";
import { AuthService } from "../../auth/auth-service";
//import { Clients } from '../../public/components/login/login'
#autoinject
export class App {
public router: Router;
private TOKEN_KEY = "session";
configureRouter(config: RouterConfiguration, router: Router): void {
this.router = router;
config.title = "Aurelia";
config.addAuthorizeStep(AuthorizeStep);
config.map([
{
route: ["", "scheduler"],
name: "scheduler",
settings: {
icon: "scheduler",
auth: true,
roles: ["Employee", "Admin"]
},
moduleId: PLATFORM.moduleName("../components/scheduler/scheduler"),
nav: true,
title: "scheduler"
},
{
route: "clients",
name: "clients",
moduleId: PLATFORM.moduleName(
"../components/clients/clientList/clientList"
),
title: "Clients",
nav: true,
settings: {
nav: [
{ href: "#clients/clientsList", title: "Client List" },
{ href: "#clients/Create", title: "Create Client" }
],
auth: true,
roles: ["Employee", "Admin"],
pos: "left"
}
},
{
route: "clients/ClientsList",
name: "clientList",
moduleId: PLATFORM.moduleName(
"../components/clients/clientList/clientList"
),
settings: {
auth: true,
roles: ["Employee", "Admin"]
}
},
{
route: "clients/create",
name: "aboutTeam",
moduleId: PLATFORM.moduleName(
"../components/clients/clientCreate/clientCreate"
),
settings: {
auth: true,
roles: ["Employee", "Admin"]
}
},
{
route: "logout",
name: "logout",
settings: {
icon: "user",
auth: true,
roles: ["Employee", "Admin"],
pos: "right"
},
moduleId: PLATFORM.moduleName("../components/auth/logout/logout"),
nav: true,
title: "Logout"
},
{
route: "not-found",
name: "not-found",
settings: {
auth: true,
roles: ["Employee", "Admin"]
},
moduleId: PLATFORM.moduleName("../components/notFound/notFound"),
nav: false,
title: "Not Found"
},
{
route: "login",
name: "login",
settings: {
icon: "user",
auth: true,
roles: ["Employee", "Admin"],
pos: "right"
},
moduleId: PLATFORM.moduleName("../../public/components/login/login"),
nav: true,
title: "login"
}
]);
config.mapUnknownRoutes("not-found");
}
}
#autoinject
class AuthorizeStep {
private endDate: any;
static loginFragment = '../../public/components/login/login';
constructor(
private authService: AuthService,
private router: Router,
private aurelia: Aurelia
) { }
run(navigationInstruction: NavigationInstruction, next: Next): Promise<any> {
return Promise.resolve()
.then(() => this.checkAuthentication(navigationInstruction, next))
.then(result => result || this.checkAuthorization(navigationInstruction, next))
.then(result => result || this.checkOrigin(navigationInstruction, next))
.then(result => result || next());
}
checkAuthentication(navigationInstruction, next) {
// Do we have a JWT?
const session = this.authService.getIdentity();
if (!session) {
this.forceReturnToPublic(next); // No JWT - back to the public root.
}
console.log("CHECKaUTHENTICATION: ", navigationInstruction.getAllInstructions().some(i => i.config.settings.auth) )
if (navigationInstruction.getAllInstructions().some(i => i.config.settings.auth)) {
// Is the token valid?
if (this.authService.hasTokenExpired(session)) {
const currentUrl = navigationInstruction.fragment + (navigationInstruction.queryString ? `?${navigationInstruction.queryString}` : '');
console.log("FRAGMENT: ", navigationInstruction.fragment);
console.log("NAVIGATE INSTRUCTION: ", navigationInstruction)
console.log('currentURL: ', currentUrl);
localStorage.setItem('origin', currentUrl);
console.log("AuthorizeStep.loginFragment", AuthorizeStep.loginFragment)
next.cancel();
console.log("and it gets here!");
return new Redirect('login');
}
}
}
checkAuthorization(navigationInstruction, next) {
var usersRole = this.authService.getUserRole();
let requiredRoles = navigationInstruction.getAllInstructions()
.map(i => i.config.settings.roles)[0];
console.log("route Roles: ", requiredRoles);
let isUserPermited = requiredRoles ? requiredRoles.some(r => r === usersRole) : true;
console.log("isUserPermited: ", isUserPermited);
if (!isUserPermited) {
this.forceReturnToPublic(next);
}
}
checkOrigin(instruction, next) {
const origin = localStorage.getItem('origin');
// Check if we were not redirected to login page and have an origin
if (instruction.fragment !== AuthorizeStep.loginFragment && origin) {
localStorage.removeItem('origin');
return next.cancel(new Redirect(origin));
}
}
forceReturnToPublic(next) {
if (localStorage.getItem('origin')) {
localStorage.removeItem('origin') // Just in case we had origin set.
}
next.cancel();
this.authService.clearIdentity();
this.router.navigate("/", { replace: true, trigger: false });
this.router.reset();
this.aurelia.setRoot("public/public/public");
}
}
In all other pipeline steps you're using return next.cancel(new Redirect()), it should be the same case, as the pipeline step expects a Next as a return value, but you return a Redirect here.
Try changing it to
return next.cancel(new Redirect('login'));
I have 2 models User and Item with many to many relation, here is the definitions:
User = sequelize.define('User', {
name: {type: Sequelize.STRING}
})
Item = sequelize.define('Item', {
name: {
type: Sequelize.STRING,
allowNull: false
}
}
User.belongsToMany(models.Item, {
as: 'items',
through: 'UserItem'
})
Item.belongsToMany(models.User, {
as: 'owners',
through: 'UserItem'
})
And my request is :
Item.findAll({
include: [{
model: User,
through: {
where: {id: 2}
}
}]
}).then(items => {
log.debug(items)
}).catch(err => {
log.error(err)
})
Then I have : Error: User is not associated to Item!
I also try this :
Item.findAll({
where: {'owners.id': 2},
include: Item.assocations.owners
}).then(items => {
debug(items)
}).catch(err => {
log.error(err)
})
But now I have Error: SQLITE_ERROR: no such column: Item.owners.id
Any ideas ?
Here is my working solution :
'use strict'
const Sequelize = require('Sequelize')
const sequelize = new Sequelize({
host: 'localhost',
dialect: 'sqlite',
// SQLite only
storage: 'database.sqlite'
})
const User = sequelize.define('user', {
name: {
type: Sequelize.STRING
}
}, {
freezeTableName: true // Model tableName will be the same as the model name
})
const Item = sequelize.define('item', {
name: {
type: Sequelize.STRING
}
}, {
freezeTableName: true // Model tableName will be the same as the model name
})
const UserItem = sequelize.define('useritem', {})
User.belongsToMany(Item, {
as: 'items',
through: 'useritem'
})
Item.belongsToMany(User, {
as: 'owners',
through: 'useritem'
})
Promise.all([
User.sync({force: true}),
Item.sync({force: true}),
UserItem.sync({force: true})])
.then(() => {
return Promise.all([
User.create({name: 'test'}),
User.create({name: 'admin'}),
Item.create({name: 'item1'}),
Item.create({name: 'item2'})])
.then(results => {
return results[2].addOwner(results[0])
}).then(() => {
return Item.findAll({
include: {model: User, as: 'owners', where:{
'id': 1
}}
}).then(items => {
console.log(items)
})
})
}).catch(err => console.log(err))
as need to be on include clause and where should be added on include too