Skip to content

Commit b2172ba

Browse files
committed
Port Laravel Starter Kit
1 parent 8fd9c7c commit b2172ba

File tree

223 files changed

+6488
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+6488
-662
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@ on:
66
branches: [main]
77

88
jobs:
9+
10+
lint_js:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 22
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm install
24+
25+
- name: Check prettier formatting
26+
run: npm run format
27+
28+
- name: Check for linting errors
29+
run: npm run lint
30+
31+
- name: Check type errors
32+
run: npm run check
33+
934
scan_ruby:
1035
runs-on: ubuntu-latest
1136

.github/workflows/deploy.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
branches: [main]
7+
types:
8+
- completed
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
if: false # deploy is disabled by default
14+
# uncomment to enable:
15+
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
16+
timeout-minutes: 20
17+
env:
18+
DOCKER_BUILDKIT: 1
19+
BUNDLE_ONLY: deploy
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Setup SSH
28+
uses: webfactory/[email protected]
29+
with:
30+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
31+
32+
- name: Set up Ruby
33+
uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: .ruby-version
36+
bundler-cache: true
37+
38+
- name: Deploy
39+
env:
40+
VERSION: ${{ github.sha }}
41+
KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}
42+
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
43+
run: bundle exec kamal deploy --version=$VERSION

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ end
6969
group :development do
7070
# Use console on exceptions pages [https://github.com/rails/web-console]
7171
gem "web-console"
72+
73+
# Use letter_opener to preview emails in the browser in development [https://github.com/ryanb/letter_opener]
74+
gem "letter_opener"
7275
end
7376

7477
group :test do

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ GEM
9696
rack-test (>= 0.6.3)
9797
regexp_parser (>= 1.5, < 3.0)
9898
xpath (~> 3.2)
99+
childprocess (5.1.0)
100+
logger (~> 1.5)
99101
concurrent-ruby (1.3.5)
100102
connection_pool (2.5.3)
101103
crass (1.0.6)
@@ -150,6 +152,12 @@ GEM
150152
thor (~> 1.3)
151153
zeitwerk (>= 2.6.18, < 3.0)
152154
language_server-protocol (3.17.0.5)
155+
launchy (3.1.1)
156+
addressable (~> 2.8)
157+
childprocess (~> 5.0)
158+
logger (~> 1.6)
159+
letter_opener (1.10.0)
160+
launchy (>= 2.2, < 4)
153161
lint_roller (1.1.0)
154162
logger (1.7.0)
155163
loofah (2.24.1)
@@ -409,6 +417,7 @@ DEPENDENCIES
409417
jbuilder
410418
js-routes
411419
kamal
420+
letter_opener
412421
propshaft
413422
puma (>= 5.0)
414423
rails (~> 8.0.2)

Procfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
vite: bin/vite dev
3-
web: bin/rails s
3+
web: bin/rails s -p 3000

README.md

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,73 @@
1-
# README
1+
# Inertia Rails Vue Starter Kit
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
3+
A modern full-stack starter application with Rails backend and Vue.js frontend using Inertia.js based on the [Laravel Starter Kit](https://github.com/laravel/vue-starter-kit).
54

6-
Things you may want to cover:
5+
## Features
76

8-
* Ruby version
7+
- [Inertia Rails](https://inertia-rails.dev) & [Vite Rails](https://vite-ruby.netlify.app) setup
8+
- [Vue.js](https://vuejs.org) frontend with TypeScript & [shadcn/vue](https://shadcn-vue.com) component library
9+
- User authentication system (based on [Authentication Zero](https://github.com/lazaronixon/authentication-zero))
10+
- [Kamal](https://kamal-deploy.org/) for deployment
11+
- Optional SSR support
912

10-
* System dependencies
13+
See also:
14+
- [React Starter Kit](https://github.com/inertia-rails/react-starter-kit) for Inertia Rails with React
1115

12-
* Configuration
16+
<a href="https://evilmartians.com/?utm_source=inertia-rails-vue-starter-kit&utm_campaign=project_page">
17+
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Built by Evil Martians" width="236" height="54">
18+
</a>
1319

14-
* Database creation
20+
## Setup
1521

16-
* Database initialization
22+
1. Clone this repository
23+
2. Setup dependencies & run the server:
24+
```bash
25+
bin/setup
26+
```
27+
3. Open http://localhost:3000
1728

18-
* How to run the test suite
29+
## Enabling SSR
1930

20-
* Services (job queues, cache servers, search engines, etc.)
31+
This starter kit comes with optional SSR support. To enable it, follow these steps:
2132

22-
* Deployment instructions
33+
1. Open `app/frontend/entrypoints/inertia.ts` and uncomment part of the `setup` function:
34+
```ts
35+
// Uncomment the following to enable SSR hydration:
36+
// if (el.hasChildNodes()) {
37+
// createSSRApp({ render: () => h(App, props) })
38+
// .use(plugin)
39+
// .mount(el)
40+
// return
41+
// }
42+
```
43+
2. Open `config/deploy.yml` and uncomment several lines:
44+
```yml
45+
servers:
46+
# Uncomment to enable SSR:
47+
# vite_ssr:
48+
# hosts:
49+
# - 192.168.0.1
50+
# cmd: bundle exec vite ssr
51+
# options:
52+
# network-alias: vite_ssr
53+
54+
# ...
55+
56+
env:
57+
clear:
58+
# Uncomment to enable SSR:
59+
# INERTIA_SSR_ENABLED: true
60+
# INERTIA_SSR_URL: "http://vite_ssr:13714"
61+
62+
# ...
63+
64+
builder:
65+
# Uncomment to enable SSR:
66+
# dockerfile: Dockerfile-ssr
67+
```
2368

24-
* ...
69+
That's it! Now you can deploy your app with SSR support.
70+
71+
## License
72+
73+
The project is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationController < ActionController::Base
24
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
35
allow_browser versions: :modern
46

7+
inertia_share flash: -> { flash.to_hash }
8+
59
before_action :set_current_request_details
610
before_action :authenticate
711

812
private
9-
def authenticate
10-
if session_record = Session.find_by_id(cookies.signed[:session_token])
11-
Current.session = session_record
12-
else
13-
redirect_to sign_in_path
14-
end
15-
end
16-
17-
def set_current_request_details
18-
Current.user_agent = request.user_agent
19-
Current.ip_address = request.ip
20-
end
13+
14+
def authenticate
15+
redirect_to sign_in_path unless perform_authentication
16+
end
17+
18+
def require_no_authentication
19+
return unless perform_authentication
20+
21+
flash[:notice] = "You are already signed in"
22+
redirect_to root_path
23+
end
24+
25+
def perform_authentication
26+
Current.session ||= Session.find_by_id(cookies.signed[:session_token])
27+
end
28+
29+
def set_current_request_details
30+
Current.user_agent = request.user_agent
31+
Current.ip_address = request.ip
32+
end
2133
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
class DashboardController < InertiaController
4+
def index
5+
end
6+
end

app/controllers/home_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
class HomeController < ApplicationController
1+
# frozen_string_literal: true
2+
3+
class HomeController < InertiaController
4+
skip_before_action :authenticate
5+
before_action :perform_authentication
6+
27
def index
38
end
49
end
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
class Identity::EmailVerificationsController < ApplicationController
1+
# frozen_string_literal: true
2+
3+
class Identity::EmailVerificationsController < InertiaController
24
skip_before_action :authenticate, only: :show
35

46
before_action :set_user, only: :show
@@ -10,17 +12,18 @@ def show
1012

1113
def create
1214
send_email_verification
13-
redirect_to root_path, notice: "We sent a verification email to your email address"
15+
redirect_back_or_to root_path, notice: "We sent a verification email to your email address"
1416
end
1517

1618
private
17-
def set_user
18-
@user = User.find_by_token_for!(:email_verification, params[:sid])
19-
rescue StandardError
20-
redirect_to edit_identity_email_path, alert: "That email verification link is invalid"
21-
end
2219

23-
def send_email_verification
24-
UserMailer.with(user: Current.user).email_verification.deliver_later
25-
end
20+
def set_user
21+
@user = User.find_by_token_for!(:email_verification, params[:sid])
22+
rescue StandardError
23+
redirect_to edit_identity_email_path, alert: "That email verification link is invalid"
24+
end
25+
26+
def send_email_verification
27+
UserMailer.with(user: Current.user).email_verification.deliver_later
28+
end
2629
end

0 commit comments

Comments
 (0)