arnoson / kirby-vite-multi-page-kit

A multi-page Kirby CMS + Vite starter kit
MIT License
37 stars 6 forks source link

How to acces http://localhost:888 via a public url #5

Closed Jorckx closed 2 years ago

Jorckx commented 2 years ago

Hi! And thanks for making the kirby-vitekit so awesome. It's an absolute pleasure to wrok with :) I'm slowly learning the core-concepts behind Vite itself. However, I seem to be unable to make the website accessible via a public url over lan/wifi.

I've added the host: true to the server settings like this:

  server: {
    cors: true,
    hmr: { host: 'localhost' },
    port: 3000,
    strictPort: true,
    host: true
  },

It exposes the network url, but when I visit it the site won't load (both on 3000 and 8888)

I was wondering if this has to do with the separation between port 3000 and 8888 which is the url I acces to preview the website.

"server": "php -S localhost:8888 -t public server.php",

Hopefully there is a simple explanation for it.

arnoson commented 2 years ago

Hey, I'm glad you like the kit!

To be honest I haven't tried to expose the website over lan/wifi. The php dev server docs warn about using it over public network. For most projects I actually use Laravel Valet instead. Valet has different options to share a website. I haven't tried it though and am not sure if it works well together with vite's dev server.

Jorckx commented 2 years ago

That totally makes sense! In the mean time it's deployed on my subdomain. So I work from that while debugging for mobile. Maybe a bit unrelated to the issue, but now it seems like the url on my subdomain will add te public folder in the url. I know it can be changed by adding some lines in the .htaccess file, but this doesn't seem to do the trick:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

The above lines I've added in the .htaccess of the root directory. The htaccess file in the public folder is still as you've set it up.

arnoson commented 2 years ago

That's strange. When you point your subdomain to the public folder (and not the project folder) it should work.

Jorckx commented 2 years ago

Yes, strange it is. I've send the same question to the hosting-provider. Maybe they block it :)

Jorckx commented 2 years ago

Hey, I'm glad you like the kit!

To be honest I haven't tried to expose the website over lan/wifi. The php dev server docs warn about using it over public network. For most projects I actually use Laravel Valet instead. Valet has different options to share a website. I haven't tried it though and am not sure if it works well together with vite's dev server.

I'm currently investigating Laravel Valet myself :) It's wonderfull! However, I seem to be unable to get the dist-files served via Valet. The html-markup loads fine though. It seems like the public folder-setup requires some additional tweaks to work with Valet. I couldn't find any resources about it yet. I'm wondering if it can be setup with this kit?

arnoson commented 2 years ago

Valet is great! Are you using valet link inside the public folder (not the project root)?

Jorckx commented 2 years ago

I've tested it both in the root as the public folder. loaded the html, but the styles and js aren't loaded.

arnoson commented 2 years ago

Okay I finally found some time. The problem is that kirby-vite uses localhost:3000 during development which of course doesn't work if you use the website oustide your local network. In order to get this to work kirby-vite would have to also expose vite's dev server and use your IP instead of localhost. I'm a bit busy right now so I don't know if and when I will find time to implement this. What you can do for now is just build your site first and then you can easily share it with valet or any other dev server.

scsskid commented 2 years ago

It's a general problem with all php/vite setups, not with this project