tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.86k stars 247 forks source link

@routes directive return url const with server IP and server port instead domain #659

Closed marcelleza8 closed 1 year ago

marcelleza8 commented 1 year ago

Ziggy version

^1.0

Laravel version

^10.0

Description

In .env file APP_URL and ASSETURL are both "http://domain.com.br/site2" I put on app.blade.php the directive @routes, after that i run "php artisan ziggy:generate", the /resources/js/ziggy.js file show the correct configuration: const Ziggy = {"url":"http:\/\/www.domain.com.br\/site2","port":null,"defaults":{},"routes":{"sanctum.csrf-cookie" ... , but when i access e check the source code, appears the server and port server: const Ziggy = {"url":"http:\/\/10.1.1.20:8083","port":8083,"defaults":{},"routes":{"sanctum.csrf-cookie":_ .... The app its inside a docker container using nginx and app with PHP services. Its first time this happend and don't know how to put the domain instead of IP address/port in to source code.

P.S = the @vite('resources/js/app.js') directive, show the correct domain

Thanks in advance

Ziggy call and context

import "../css/app.css";
import "sweetalert2/dist/sweetalert2.min.css";
import "vue3-carousel/dist/carousel.css";
import "@splidejs/vue-splide/css";

import { createApp, h } from "vue";
import { createInertiaApp } from "@inertiajs/inertia-vue3";
import { InertiaProgress } from "@inertiajs/progress";
import { resolvePageComponent } from "laravel-vite-plugin/inertia-helpers";
import { ZiggyVue } from "../../vendor/tightenco/ziggy/dist/vue.m";
import VueSweetalert2 from "vue-sweetalert2";
import VueSplide from "@splidejs/vue-splide";

/* https://fontawesome.com/docs/web/use-with/vue/add-icons */
/* import the fontawesome core */
import { library } from "@fortawesome/fontawesome-svg-core";
/* import font awesome icon component */
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
/* import specific icons */
import {
    faUser,
    faAdd,
    faPen,
    faTrashCan,
} from "@fortawesome/free-solid-svg-icons";
/* add icons to the library */
library.add(faUser, faAdd, faPen, faTrashCan);

const appName =
    window.document.getElementsByTagName("title")[0]?.innerText ||
    "Site name";

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) =>
        resolvePageComponent(
            `./Pages/${name}.vue`,
            import.meta.glob("./Pages/**/*.vue")
        ),
    setup({ el, app, props, plugin }) {
        return createApp({ render: () => h(app, props) })
            .use(plugin)
            .use(ZiggyVue, Ziggy)
            .use(VueSweetalert2)
            .use(VueSplide)
            .component("font-awesome-icon", FontAwesomeIcon)
            .mount(el);
    },
});

InertiaProgress.init({ color: "#4B5563", showSpinner: true });

Ziggy configuration

// this is what appears on source page, in resources/js/ziggy.js shows url and port columns correctly.
const Ziggy = {
  url: "http://10.1.1.20:8083",
  port: 8083,
  defaults: {},
  routes: {
    "sanctum.csrf-cookie": {
      uri: "sanctum/csrf-cookie",
      methods: ["GET", "HEAD"],
    },
    "ignition.healthCheck": {
      uri: "_ignition/health-check",
      methods: ["GET", "HEAD"],
    },
    "ignition.executeSolution": {
      uri: "_ignition/execute-solution",
      methods: ["POST"],
    },
    "ignition.updateConfig": {
      uri: "_ignition/update-config",
      methods: ["POST"],
    },
    "site.home": { uri: "/", methods: ["GET", "HEAD"] },
    "site.historia": { uri: "historia", methods: ["GET", "HEAD"] },
    "site.premios": { uri: "premios", methods: ["GET", "HEAD"] },
    "site.marcas": { uri: "marcas", methods: ["GET", "HEAD"] },
    "site.sustentabilidade": {
      uri: "sustentabilidade",
      methods: ["GET", "HEAD"],
    },
    "site.programa-germinar": {
      uri: "programa-germinar",
      methods: ["GET", "HEAD"],
    },
    "site.programa-ideias-resultados": {
      uri: "programa-ideias-resultados",
      methods: ["GET", "HEAD"],
    },
    "site.programa-bem-estar": {
      uri: "programa-bem-estar",
      methods: ["GET", "HEAD"],
    },
    "site.programa-incluir-mais": {
      uri: "programa-incluir-mais",
      methods: ["GET", "HEAD"],
    },
    "site.programa-4ds": { uri: "programa-4ds", methods: ["GET", "HEAD"] },
    "site.fale-conosco.index": {
      uri: "fale-conosco",
      methods: ["GET", "HEAD"],
    },
    "site.fale-conosco.send-email": {
      uri: "fale-conosco/enviar",
      methods: ["POST"],
    },
    "site.envie-seu-curriculo.index": {
      uri: "envie-seu-curriculo",
      methods: ["GET", "HEAD"],
    },
    "site.envie-seu-curriculo.send": {
      uri: "envie-seu-curriculo/enviar",
      methods: ["POST"],
    },
    register: { uri: "register", methods: ["GET", "HEAD"] },
    login: { uri: "login", methods: ["GET", "HEAD"] },
    "password.request": { uri: "forgot-password", methods: ["GET", "HEAD"] },
    "password.email": { uri: "forgot-password", methods: ["POST"] },
    "password.reset": {
      uri: "reset-password/{token}",
      methods: ["GET", "HEAD"],
    },
    "password.update": { uri: "reset-password", methods: ["POST"] },
    "verification.notice": { uri: "verify-email", methods: ["GET", "HEAD"] },
    "verification.verify": {
      uri: "verify-email/{id}/{hash}",
      methods: ["GET", "HEAD"],
    },
    "verification.send": {
      uri: "email/verification-notification",
      methods: ["POST"],
    },
    "password.confirm": { uri: "confirm-password", methods: ["GET", "HEAD"] },
    logout: { uri: "logout", methods: ["POST"] },
  },
};

Route definition

// Default routes
bakerkretzmar commented 1 year ago

The @routes Blade directive uses the URL of the current request, not your APP_URL. Are you visiting the app in your browser at http://10.1.1.20:8083? If you are, that's the issue.

If not, it may have something to do with your Docker container setup. If the request is being forwarded through any kind of proxy or Laravel is running on a different host than the webserver, make sure your Trusted Proxies and Trusted Hosts are configured.