laravel / nova-issues

557 stars 34 forks source link

Apache root's subfolder ref #181 #471

Closed num3r06 closed 5 years ago

num3r06 commented 6 years ago

Hi In reference a #181 In windows my development environment it's a bitnami wampstack with apache. My laravel app it's in a root subfolder's http://localhost/ater/public and work fine. When I've installed nova the admin panel search the asset on root folder's and obviusly not found. with php artisan serve works There's a way for using nova in this mode? img This is a fresh installation of laravel with nova 1.0.12 Thx

fletch3555 commented 6 years ago

The asset() helper method uses your APP_URL to determine what path to use. You likely need to update APP_URL in your .env file to include "ater/public". This is almost 100% not specific to Nova

num3r06 commented 6 years ago

in nova's layout.blade.php it's not used asset() helper but mix() helper:

<link rel="stylesheet" href="{{ mix('app.css', 'nova-assets') }}">

i change APP_URL in the .env file but nothing change this is my .env


APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
APP_DEBUG=true
APP_URL=http://localhost/ater/public/

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3307
DB_DATABASE=ater
DB_USERNAME=root
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

``
the ater folder it's a subfolder of root's apache folder
flashadvocate commented 6 years ago

Having the same issue. The problem is, the mix-manifest does not take into account the app URL, or the possibility that the application is not in the root path. IE www.site.com/laravel-app/.

num3r06 commented 6 years ago

Any chance for this. I don't want to use Valet or Doker for development and the only solution for locally development on windows it's a wamp server with many root's directory subfolder (i use bitnami wampstack)

AegirLeet commented 6 years ago

Why don't you use php artisan serve for local development?

num3r06 commented 6 years ago

Yes i can but i want to know if it's possible using nova in a subfolder

flashadvocate commented 6 years ago

Worth noting that this is not just a local development issue. It’s extremely likely that laravel is used in a production environment that warrants deploying in a sub folder

AegirLeet commented 6 years ago

... That might work.

flashadvocate commented 6 years ago

Well yeah, until you need to update Nova to the latest release. We shouldn't need to manually make this change.

fletch3555 commented 6 years ago

No you shouldn't have to. Perhaps this is a unpopular opinion, but I don't believe you should ever need to install laravel in a subfolder, production or otherwise. Vhosts are free and easy to set up. Subdomains are free once you own the domain they fall under. Just take the time to set it up "right" and you won't haa any of these problems

flashadvocate commented 6 years ago

Yeah, unfortunately that's not always true. I work for a university where 3rd-level domains are a premium, and are rarely given out except under very specific circumstances. Nova shouldn't make assumptions about the deployment strategy for an application, and for the record, installing a laravel app in a subfolder is not "the wrong way", considering the base framework supports this just fine. It should be flexible enough to support whatever APP_URL is set to. This is not a large ask.

ben182 commented 6 years ago

couldn't this easily be fixed by replacing <link rel="stylesheet" href="{{ mix('app.css', 'nova-assets') }}"> with <link rel="stylesheet" href="{{ asset(mix('app.css', 'nova-assets')) }}">?

markgp commented 6 years ago

That only gets the assets loading. All of the API endpoints are hard-coded to /nova-api throughout the application.

Etmolf commented 6 years ago

Why not create a proper vHost Configuration or at least use RewriteBase /yoursubfolder in your .htaccess :-)

num3r06 commented 6 years ago

My subfolder's name is ater. Can you help me to write the .htaccess file correctly thanks a lot

albalooshi commented 5 years ago

Try adding alias for both nova and nova-api in httpd.conf, then restart apache.

Alias "/nova" "/var/www/html/ater/public/nova"
Alias "/nova-api" "/var/www/html/ater/public/nova-api"

Where /var/www/html/ater/public/nova is the full path to nova.

num3r06 commented 5 years ago

I try but not works

albalooshi commented 5 years ago

@num3r06 it worked for me, try restarting the apache server.

num3r06 commented 5 years ago

Adding also this works
Alias /vendor/nova /var/www/html/ater/public/vendor/nova thx

num3r06 commented 5 years ago

Sorry, All works fine but nova-api path seems to be hardcoded and not configurable. There's a chance to overwrite this path?

Dennis1000 commented 5 years ago

Nova needs to honor the APP_URL .env-setting, all other comments about cheap subdomains, etc are totally senseless. Oh yeah, and the "solution" by adding an alias to the vhosts conf is useless, too if one needs more than a single Nova installation on one domain/subdomain.

fouedmoussi commented 5 years ago

I have same issue and i have tried adding asset() helper to every mix() call in nova blade resources, Now i'm getting 404 !! Screen Shot 2019-06-18 at 08 45 44 (2)

chinleung commented 5 years ago

For anyone who has issue installing it in a subfolder, this is how I got it working for me: https://gist.github.com/chinleung/2e9f6a9496ded8cd6fadc829b0030229

alihbuzaid commented 5 years ago

is there any good solution for this issue ?

klimov-paul commented 5 years ago

You may use illuminatech/override-build to apply @chinleung's patch.

Assuming your domain is 'http://test.devel' and subfolder named 'subfolder, the configuration for it will be following:

<?php
// file 'config/override-build.php'
return [
    'packages' => [
        'nova' => [
            'srcPath' => base_path('vendor/laravel/nova'),
            'buildPath' => base_path('vendor/laravel/nova'),
            'patches' => [
                'resources/js/util/axios.js' => [
                    '__class' => Illuminatech\OverrideBuild\Patches\Replace::class,
                    'replaces' => [
                        'axios.create()' => "axios.create({baseURL: 'http://test.devel/subfolder'})"
                    ],
                ],
                'resources/views/layout.blade.php' => [
                    '__class' => Illuminatech\OverrideBuild\Patches\Replace::class,
                    'replaces' => [
                        '"/nova-api/' => '"/subfolder/nova-api/',
                        "mix('app.css', 'vendor/nova')" => "asset(mix('app.css', 'vendor/nova'))",
                        "mix('manifest.js', 'vendor/nova')" => "asset(mix('manifest.js', 'vendor/nova'))",
                        "mix('vendor.js', 'vendor/nova')" => "asset(mix('vendor.js', 'vendor/nova'))",
                        "mix('app.js', 'vendor/nova')" => "asset(mix('app.js', 'vendor/nova'))",
                        '@json(Nova::jsonVariables(request()));' => "@json(Nova::jsonVariables(request()));\nwindow.config.base = '/subfolder' + window.config.base;"
                    ],
                ],
            ],
            'buildCommand' => [
                'mv webpack.mix.js.dist webpack.mix.js',
                'yarn install',
                'yarn run '.((env('APP_ENV') === 'production') ? 'prod' : 'dev'),
            ],
        ],
    ],
]

Rebuild command:

php artisan override-build nova

It will still leave the login form CSS messed up, but you can figure it up.

klimov-paul commented 5 years ago

In order to make it better without messing up 'vendor' directory, you may use separated directory for the JS build exporting results to 'public/vendor/nova'. The config for this will be:

<?php
// file 'config/override-build.php'
return [
    'packages' => [
        'nova' => [
           'srcPath' => base_path('vendor/laravel/nova'),
            'buildPath' => storage_path('build-override/nova'),
            'srcFiles' => [
                'resources',
                '.babelrc',
                'mix-manifest.json',
                'package.json',
                'tailwind.js',
                'webpack.mix.js.dist',
                'yarn.lock',
            ],
            'patches' => [
                'resources/js/util/axios.js' => [
                    '__class' => Illuminatech\OverrideBuild\Patches\Replace::class,
                    'replaces' => [
                        'axios.create()' => "axios.create({baseURL: 'http://test.devel/subfolder'})"
                    ],
                ],
                'webpack.mix.js.dist' => [
                    '__class' => Illuminatech\OverrideBuild\Patches\Replace::class,
                    'replaces' => [
                        ".copy('public', '../nova-app/public/vendor/nova')" => ".copy('public', '../../public/vendor/nova')",
                    ],
                ],
                'resources/views/layout.blade.php' => [
                    '__class' => Illuminatech\OverrideBuild\Patches\Replace::class,
                    'replaces' => [
                        '"/nova-api/' => '"/subfolder/nova-api/',
                        "mix('app.css', 'vendor/nova')" => "asset(mix('app.css', 'vendor/nova'))",
                        "mix('manifest.js', 'vendor/nova')" => "asset(mix('manifest.js', 'vendor/nova'))",
                        "mix('vendor.js', 'vendor/nova')" => "asset(mix('vendor.js', 'vendor/nova'))",
                        "mix('app.js', 'vendor/nova')" => "asset(mix('app.js', 'vendor/nova'))",
                        '@json(Nova::jsonVariables(request()));' => "@json(Nova::jsonVariables(request()));\nwindow.config.base = '/subfolder' + window.config.base;"
                    ],
                ],
            ],
            'buildCommand' => [
                'yarn install',
                'yarn run '.((env('APP_ENV') === 'production') ? 'prod' : 'dev'),
            ],
        ],
    ],
]

Rebuild command:

php artisan override-build nova

Once build is complete you should manually move layout file from 'storage/build-override/nova/resources/views/layout.blade.php' to 'resources/views/vendor/nova/layout.blade.php' using native Nova view override principle.

tpetry commented 5 years ago

I submitted a simple patch long time ago (you need to activate access to the repository within the nova buying application settings) but the developers decided to not include it. I attached the patch to this comment. I am applying this patch for a long time and it's working for every new version without any problems or conflicts (you need to rebuild the assets after patching). My patch has a few more lines changed compared to the changes by @klimov-paul because i tries to make the most simple fundamental changes so nova plugins work without any problems too.

Attachment: nova-subfolder-support.patch.txt

jbrooksuk commented 5 years ago

I appreciate that this is not going to be to everybody's liking, but I'm closing this issue. Reasons being:

  1. Laravel is not meant to be installed from a sub-directory, so making this work would go against best practises and potentially introduce security issues that Laravel does not account for.
  2. Supporting sub-directories would introduce more work for the core team, which is not something we want to do at this time.
  3. If you wish to run Nova under a sub-directory, @tpetry has a patch that is available above and you do so at your own risk.
klimov-paul commented 5 years ago

@jbrooksuk, I afford to remind you, that we are not talking about free open-source project here. Everyone here have payed money for the Laravel Nova access.

If this is your resolve, you should make a refund to every participant of this conversation, as, in fact, you have sold them product, which is broken, and you refuse to fix it up.

davidhemphill commented 5 years ago

It's not broken, you just don't like the outcome, which is based on already-established best practices for Laravel. Locking.