Skip to content

Commit 5df99e1

Browse files
committed
Initial commit
0 parents  commit 5df99e1

19 files changed

+2227
-0
lines changed

.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
*.bat
27+
28+
caddy.exe

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
3+
}

Caddyfile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
# global options
3+
admin off # theres no need for the admin api in railway's environment
4+
persist_config off # storage isn't persistent anyway
5+
auto_https off # railway handles https for us, this would cause issues if left enabled
6+
log {
7+
# runtime logs
8+
format json # set runtime log format to json mode
9+
}
10+
servers {
11+
# server options
12+
trusted_proxies static private_ranges # trust railway's proxy
13+
}
14+
}
15+
16+
:{$PORT} {
17+
# site block, listens on the $PORT environment variable, automatically assigned by railway
18+
log {
19+
# access logs
20+
format json # set access log format to json mode
21+
}
22+
23+
# health check for railway
24+
respond /health 200
25+
26+
# serve from the 'dist' folder (Vite builds into the 'dist' folder)
27+
root * dist
28+
29+
# enable gzipping responses
30+
encode gzip
31+
32+
# serve files from 'dist'
33+
file_server
34+
35+
# if path doesn't exist, redirect it to 'index.html' for client side routing
36+
try_files {path} /index.html
37+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Railway
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Vue 3 + TypeScript + Vite + Caddy
3+
description: The default Vue + Vite TS starter, utilizing `Caddy` to serve the built single page app
4+
tags:
5+
- Node
6+
- Vue 3
7+
- Vite
8+
- TypeScript
9+
- Caddy
10+
---
11+
12+
# Vue 3 + TypeScript + Vite + Caddy
13+
14+
This template should help get you started developing with Vue and TypeScript in Vite. The template uses Vue 3 With TypeScript.
15+
16+
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/Qh0OAU?referralCode=ySCnWl)
17+
18+
## ✨ Features
19+
20+
- Vue 3 + TypeScript + Vite + Caddy
21+
- Caddy v2
22+
23+
## 💁‍♀️ Local Development
24+
25+
- Install required dependencies with `npm install`
26+
- Start the server for local development `npm run dev`
27+
- Navigate to `http://localhost:5173/. The application will automatically reload if you change any of the source files.
28+
29+
## ❓ Why use `Caddy` when deploying to Railway?
30+
31+
Caddy is a powerful, enterprise-ready, open source web server, and therefore Caddy is far better suited to serve websites than Vite is, using Caddy will result in much less memory and cpu usage compared to serving with Vite (much lower running costs too)
32+
33+
To see how this is achieved with nixpacks, check out the fully documented nixpacks.toml file in this repository
34+
35+
The configuration for Caddy is called a Caddyfile, and you can edit that file to further suite your needs, by default it comes configured to serve a single page app for Vue 3, and to also gzip the responses
36+
37+
**Relevant Caddy documentation:**
38+
39+
- [The Caddyfile](https://caddyserver.com/docs/caddyfile)
40+
- [Caddyfile Directives](https://caddyserver.com/docs/caddyfile/directives)
41+
- [root](https://caddyserver.com/docs/caddyfile/directives/root)
42+
- [encode](https://caddyserver.com/docs/caddyfile/directives/encode)
43+
- [file_server](https://caddyserver.com/docs/caddyfile/directives/file_server)
44+
- [try_files](https://caddyserver.com/docs/caddyfile/directives/try_files)

index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + Vue + TS</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

nixpacks.toml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# https://nixpacks.com/docs/configuration/file
2+
3+
# set up some variables to minimize annoyance
4+
[variables]
5+
NPM_CONFIG_UPDATE_NOTIFIER = 'false' # the update notification is relatively useless in a production environment
6+
NPM_CONFIG_FUND = 'false' # the fund notification is also pretty useless in a production environment
7+
8+
# download caddy from nix
9+
[phases.caddy]
10+
dependsOn = ['setup'] # make sure this phase runs after the default 'setup' phase
11+
nixpkgsArchive = 'ba913eda2df8eb72147259189d55932012df6301' # Caddy v2.8.4 - https://github.com/NixOS/nixpkgs/commit/ba913eda2df8eb72147259189d55932012df6301
12+
nixPkgs = ['caddy'] # install caddy as a nix package
13+
14+
# format the Caddyfile with fmt
15+
[phases.fmt]
16+
dependsOn = ['caddy'] # make sure this phase runs after the 'caddy' phase so that we know we have caddy downloaded
17+
cmds = ['caddy fmt --overwrite Caddyfile'] # format the Caddyfile to fix any formatting inconsistencies
18+
19+
# start the caddy web server
20+
[start]
21+
cmd = 'exec caddy run --config Caddyfile --adapter caddyfile 2>&1' # start caddy using the Caddyfile config and caddyfile adapter

0 commit comments

Comments
 (0)