I have a gatsbyjs app with client-only routes that works fine locally but in production I can only access those routes when following a link but when typing the url directly in the browser i get a 404.
I had expected following the answer in this thread, but issue persists. Any hints or suggestions?
// app.json
{
"name": "User Resource",
"repository": "https://github.com/guanacone/fullstack_app",
"stack": "container",
"buildpacks": [
{
"url": "heroku/nodejs"
},
{
"url": "https://github.com/heroku/heroku-buildpack-static"
}
]
}
//static.json
{
"root": "public/",
"clean_urls": true,
"routes": {
"/user/**": "user/index.html"
}
}
// gatsby-config.js
module.exports = {
/* Your site config here */
plugins: [
'gatsby-plugin-layout',
{
resolve: 'gatsby-plugin-create-client-paths',
options: { prefixes: ['/user/*'] },
},
'gatsby-plugin-styled-components',
'gatsby-plugin-use-query-params',
],
};
// src/pages/user.js
import React from 'react';
import { Router } from '#reach/router';
import UserIndex from '../components/UserIndex';
import UserProfile from '../components/UserProfile';
import UserNew from '../components/UserNew';
import UserEdit from '../components/UserEdit';
import UserActivation from '../components/UserActivation';
const User = () => (
<Router basepath='/user'>
<UserIndex path='/' />
<UserProfile path='/:id' />
<UserNew path='/new' />
<UserEdit path='/:id/edit' />
<UserActivation path='/activation' />
</Router>
);
export default User;
I solved it by removing the heroku-buildpack-static and adding the following code to my express.js server.
app.get('/user/**', (req, res) => {
res.sendFile(path.join(`${__dirname}/public/user/index.html`));
});
Related
I am getting an error when starting a dev server:
Error: EPERM: operation not permitted, scandir '/var/www/html/rootfs/host_mnt/c
I have a Laravel - Inertia - Vue3 application that I am trying to build with Vite for development.
From vite.config.js
import {defineConfig} from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '#vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel({
input: 'resources/js/app.js',
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
]
});
devcontainer.json
{
"name": "Mangrove Development Environment",
"dockerComposeFile": [
"../docker-compose.yml"
],
"service": "mangrove",
"workspaceFolder": "/var/`your text`www/html",
"settings": {},
"customizations": {
"vscode": {
"extensions": [
"felixfbecker.php-debug",
"ms-vsliveshare.vsliveshare",
"eamodio.gitlens",
"bmewburn.vscode-intelephense-client",
"mikestead.dotenv",
"amiralizadeh9480.laravel-extra-intellisense",
"ryannaddy.laravel-artisan",
"onecentlin.laravel5-snippets",
"onecentlin.laravel-blade",
"EditorConfig.EditorConfig",
"jcbuisson.vue",
"redhat.vscode-yaml"
]
}
},
"remoteUser": "sail",
//"postCreateCommand": "chown -R 1000:1000 /var/www/html"
"postCreateCommand": ""
// "forwardPorts": [],
// "runServices": [],
// "shutdownAction": "none",
}
I tried using "postCreateCommand": "chown -R 1000:1000 /var/www/html" in the devcontainer.json file, but this simply tries to turn over ownership of every single file on my Windows system's hard drive.
I have also tried inserting
server: {
watch: {
ignored: [
"rootfs/**/*",
],
}
}
Into the vite.config.js to perhaps ignore those files.
I'm implementing fullcalendar in my project that has Laravel 9 and Vue 3.
I think it is not loading the css as the on-screen calendar is looking like this: Calendar Image.
I have already made several settings. Even the Vue part is working because the calendar is working.
Below in the images are the settings that are today.
package.json
{
"private": true,
"scripts": {
"dev": "vite --host",
"build": "vite build"
},
"devDependencies": {
"axios": "^1.1.2",
"bootstrap": "^4.6.2",
"laravel-vite-plugin": "^0.6.0",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"sass": "^1.32.11",
"script-loader": "^0.7.2",
"vite": "^3.0.0"
},
"dependencies": {
"#fullcalendar/core": "^5.11.3",
"#fullcalendar/daygrid": "^5.11.3",
"#fullcalendar/interaction": "^5.11.3",
"#fullcalendar/list": "^5.11.3",
"#fullcalendar/timegrid": "^5.11.3",
"#fullcalendar/vue3": "^5.11.2",
"#popperjs/core": "^2.11.6",
"#vitejs/plugin-vue": "^3.1.2",
"laravel-echo": "^1.9.0",
"socket.io-client": "^2.3.0",
"vue": "^3.2.41",
"vue-toastification": "^2.0.0-rc.5"
}
}
vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '#vitejs/plugin-vue';
import fs from 'fs';
const host = 'site.com.br';
export default defineConfig({
plugins: [
laravel({
input: ['resources/sass/app.scss', 'resources/js/app.js'],
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
}
}
})
],
server: {
host,
hmr: { host },
https: {
key: fs.readFileSync('C:\\laragon\\etc\\ssl\\privada25296.key'),
cert: fs.readFileSync('C:\\laragon\\etc\\ssl\\certificado25296.crt'),
},
},
});
index.vue
<script>
import { useToast } from "vue-toastification";
import '#fullcalendar/core/vdom' // solves problem with Vite
import FullCalendar from '#fullcalendar/vue3'
import dayGridPlugin from '#fullcalendar/daygrid'
import timeGridPlugin from '#fullcalendar/timegrid'
import interactionPlugin from '#fullcalendar/interaction'
import { INITIAL_EVENTS, createEventId } from './event-utils'
export default {
components: {
FullCalendar // make the <FullCalendar> tag available
},
data() {
return {
calendarOptions: {
plugins: [ dayGridPlugin, timeGridPlugin, interactionPlugin ],
initialView: 'dayGridMonth',
initialEvents: INITIAL_EVENTS, // alternatively, use the `events` setting to fetch from a feed
}
}
},
mounted() {
const toast = useToast();
this.loadUserCustomers();
Echo.channel('agendamentos_database_user_customer_created')
.listen('UserCustomerCreated', (e) => {
toast.success('Novo cliente vinculado!')
});
},
methods: {
loadUserCustomers() {
axios.get('/api/calendar')
.then(response => {
console.log( response.data.data );
//this.userCustomers = response.data
})
.catch(response => {
console.log('Erro')
})
}
},
}
In the fullcalendar documentation, the following is mentioned about CSS.
CSS: All of FullCalendar’s CSS will be automatically loaded as long as your build system is able to process .css file imports. See Initializing with an ES6 Build System for more information on configuring your build system. https://fullcalendar.io/docs/vue#:~:text=ticket%20%23152.-,CSS,-All%20of%20FullCalendar%E2%80%99s
When I access link about ES6 Build System, it is described that I need to use webpack, and in the Laravel application, vite is used.
Can anyone help me with this problem please?
I solved it by loading allocate the size of the calendar
hope this solve your problem and I did it with the cdn
calendar.render();
calendar.setOption('height', 700);
I'm using Laravel 9 application. Laravel latest version has replaced webpack to vite. I was able to successfully run the app into my local environment but, while deploying the compiled assets to the AWS S3 I'm getting CORS error in the browser console.
Steps I did after running in local environment.
added ASSET_URL=https://****.s3.ap-south-1.amazonaws.com in my .env file
run npm run build
run aws s3 sync public/ s3://****/ --delete --exclude index.php --acl public-read
I can see that my .css and other files are loaded perfectly, but I'm getting CORS error only in the compiled js file.
I also added policy in my s3 bucket:
{
"Version": "2012-10-17",
"Id": "Policy1617109982386",
"Statement": [
{
"Sid": "Stmt1617109981105",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::****/*"
}
]
}
But this isn't helping me out.
My Vite config file looks like:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '#vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel({
input: 'resources/js/app.js',
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
});
I also tried declaring cors in vite.config.js file:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '#vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel({
input: 'resources/js/app.js',
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
server: {
cors: true
}
});
I'm unable to find any solution. Help me out.
Thanks.
Hey Have a look at setting CORS in the s3 bucket.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html
I am trying to build a NextJs blog website with Strapi+ graphql. But after following the steps given by the official strapi video source I stuck with this issue in the home.jsx file...
Error: Error serializing props returned from `getStaticProps` in "/".
Reason: Props must be returned as a plain object from getStaticProps: `{ props: { ... } }` (received: `[object Undefined]`).
Here is the Home.jsx page codes:
import { Fragment } from "react";
import HomePage from "./home/home";
import { ApolloClient, InMemoryCache, gql } from "#apollo/client";
export async function getStaticProps() {
const client = new ApolloClient({
url: "http:/localhost:1337/graphql",
cache: new InMemoryCache(),
});
const GET_BLOGS = gql`
query getBlogs {
blogs {
id: string
title: string
}
}
`;
let getData = client.query({ query: GET_BLOGS });
console.log("" + getData);
return { props: getData.blogs };
}
export default function Home({ blogs }) {
if (blogs) return console.log(blogs);
return (
<Fragment>
<HomePage />
</Fragment>
);
}
Maybe dependency issue with next and strapi package.json file so here are dependencies of both:
Nextjs package.json dependencies-
"dependencies": {
"#apollo/client": "^3.4.17",
"axios": "^0.24.0",
"graphql": "^16.0.1",
"next": "12.0.2",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-toastify": "^8.1.0"
},
Strapi project dependencies:
"dependencies": {
"knex": "0.21.18",
"sqlite3": "5.0.0",
"strapi": "3.6.8",
"strapi-admin": "3.6.8",
"strapi-connector-bookshelf": "3.6.8",
"strapi-plugin-content-manager": "3.6.8",
"strapi-plugin-content-type-builder": "3.6.8",
"strapi-plugin-email": "3.6.8",
"strapi-plugin-graphql": "3.6.8",
"strapi-plugin-i18n": "3.6.8",
"strapi-plugin-upload": "3.6.8",
"strapi-plugin-users-permissions": "3.6.8",
"strapi-utils": "3.6.8"
},
"engines": {
"node": ">=10.16.0 <=14.x.x",
"npm": "^6.0.0"
},
You can check below options for your case and see if it works.
1. Try to do finalData = getData.json(), and then destruce it like finalData.blogs()
2. Const finalData = JSON.Stringify(getData); and then use final data.
The network calls response need to be serialised in jsx, and by applying above two cases you can resolve the issue
Im trying to add translations to spartacus. I managed to change config and have the regular translation JSON on my local, but when I try to add new translations to my HTML i always get the same issue:
"ERROR Error: The pipe 'cxTranslate' could not be found!"
This is what I have in my code:
<label for="sortDocType">Type of document: {{ 'common.back' | cxTranslate }}</label>
And my config Module:
import { ConfigModule, I18nConfig } from '#spartacus/core';
import { NgModule } from '#angular/core';
import { translationChunksConfig } from '#spartacus/assets';
#NgModule({
declarations: [],
imports: [
ConfigModule.withConfig({
i18n: {
backend: {
loadPath: '../../assets/i18n-assets/{{lng}}/{{ns}}.json'
},
chunks: {
...translationChunksConfig,
},
fallbackLang: 'en'
},
} as I18nConfig)
],
})
Please import I18nModule in the same module that declares your custom component:
#NgModule({
imports: [
I18nModule,
/*...*/
],
declarations: [
MyComponent,
/*...*/
],
/*...*/
})
export class MyModule {}