-
-
Save james2doyle/d9f1a4509b68077bd72c78a3b58fdeca to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* NuxtValetDriver for running compiled nuxt.js sites | |
*/ | |
class NuxtValetDriver extends BasicValetDriver | |
{ | |
/** | |
* Determine if the driver serves the request. | |
* | |
* @param string $sitePath | |
* @param string $siteName | |
* @param string $uri | |
* @return bool | |
*/ | |
public function serves($sitePath, $siteName, $uri) | |
{ | |
return is_dir($sitePath . '/dist/_nuxt'); | |
} | |
/** | |
* Get the fully resolved path to the application's front controller. | |
* | |
* @param string $sitePath | |
* @param string $siteName | |
* @param string $uri | |
* @return string | |
*/ | |
public function frontControllerPath($sitePath, $siteName, $uri) | |
{ | |
$_SERVER['PHP_SELF'] = $uri; | |
$_SERVER['SERVER_ADDR'] = '127.0.0.1'; | |
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; | |
return parent::frontControllerPath($sitePath, $siteName, '/dist' . $uri); | |
} | |
public function isStaticFile($sitePath, $siteName, $uri) | |
{ | |
// handle subfolder index pages | |
$try_html = $sitePath . '/dist' . $uri . '/index.html'; | |
if (file_exists($try_html)) { | |
return $try_html; | |
} | |
// handle public static files | |
$try_uri = $sitePath . '/dist' . $uri; | |
if (file_exists($try_uri)) { | |
return $try_uri; | |
} | |
// handle the component files | |
$path = '_nuxt/'; | |
if (false !== ($pos = stripos($uri, '/' . $path))) { | |
$new_uri = '/dist' . substr($uri, $pos); | |
if (file_exists($sitePath . $new_uri)) { | |
return $sitePath . $new_uri; | |
} | |
} | |
return parent::isStaticFile($sitePath, $siteName, $uri); | |
} | |
} |
This allows you to run a nuxt site by either having the folder your parked domains list or by using valet link
.
You should looking into valet link
. It should give you what you want
@james2doyle what about Nuxt slug pages?
it can't detect this:
'/posts/:slug' => '/post/my-new-tutorial'
@mehrencodes it should be able to detect that as long as the pages have been prerendered with nuxt generate
Hi, does this work on when I run nuxt on development (npm run dev)?
If you use the Valet URL with the port of the dev server it should work fine. Your dev server needs to be running on localhost. I am using this feature now on a react project. I have a dev server running on port 3000 and I am accessing that through myvaleturl.localhost:3000
since valet just takes over localhost
Does this configuration allow to have for example Laravel on
backend.test
and the Nuxt app on subdomainnuxt.backend.test
? But then, how aboutnpm run dev
which serves the Nuxt app onlocalhost:3000
? Also, where do you install this file ?