Skip to content

Commit 2a2c8e9

Browse files
authored
Merge pull request #9 from laravel/route-updates
Redirect homepage and handle invalid name
2 parents bbb5c72 + c2ebecc commit 2a2c8e9

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

routes/web.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
use Illuminate\Http\Request;
44
use Illuminate\Support\Facades\Route;
55
use Illuminate\Support\Facades\Validator;
6+
use Illuminate\Validation\ValidationException;
67

7-
/*
8-
|--------------------------------------------------------------------------
9-
| Web Routes
10-
|--------------------------------------------------------------------------
11-
|
12-
| Here is where you can register web routes for your application. These
13-
| routes are loaded by the RouteServiceProvider within a group which
14-
| contains the "web" middleware group. Now create something great!
15-
|
16-
*/
8+
Route::redirect('/', 'https://laravel.com/docs', 302);
179

1810
Route::get('/{name}', function (Request $request, $name) {
19-
Validator::validate(['name' => $name], ['name' => 'string|alpha_dash']);
11+
try {
12+
Validator::validate(['name' => $name], ['name' => 'string|alpha_dash']);
13+
} catch (ValidationException $e) {
14+
return response('Invalid site name. Please only use alpha-numeric characters, dashes, and underscores.', 400);
15+
}
2016

2117
$php = $request->query('php', '81');
2218

tests/Feature/SailServerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
class SailServerTest extends TestCase
88
{
9+
public function test_the_homepage_redirects_to_the_laravel_docs()
10+
{
11+
$this->get('/')->assertRedirect('https://laravel.com/docs');
12+
}
13+
914
public function test_it_can_return_the_sail_install_script()
1015
{
1116
$response = $this->get('/example-app');
@@ -30,4 +35,12 @@ public function test_it_adds_the_devcontainer_upon_request()
3035
$response->assertStatus(200);
3136
$response->assertSee('bash -c "laravel new example-app && cd example-app && php ./artisan sail:install --with=postgres --devcontainer"', false);
3237
}
38+
39+
public function test_it_does_not_accepts_domains_with_a_dot()
40+
{
41+
$response = $this->get('/foo.test');
42+
43+
$response->assertStatus(400);
44+
$response->assertSee('Invalid site name. Please only use alpha-numeric characters, dashes and underscores.');
45+
}
3346
}

0 commit comments

Comments
 (0)