Skip to content

Commit 02ee015

Browse files
committed
chore: add localias configuration for npmx.test
1 parent c28f514 commit 02ee015

File tree

6 files changed

+167
-0
lines changed

6 files changed

+167
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ file-tree-sprite.svg
4545

4646
# output
4747
.vercel
48+
49+
# Local development certificates (if using manual mkcert)
50+
*.pem
51+
*.key
52+
*.crt
53+
!public/**/*.{pem,key,crt}
54+
.localias-certs/

.localias.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Localias configuration
2+
# See: https://github.com/peterldowns/localias
3+
# Usage: localias set npmx.test 3000
4+
# Visit: https://npmx.test
5+
6+
- from: npmx.test
7+
to: http://127.0.0.1:3000

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,31 @@ This focus helps guide our project decisions as a community and what we choose t
9595
pnpm npmx-connector
9696
```
9797

98+
### Optional: Custom Local Domain
99+
100+
Configure dev server to run at `http://npmx.test:3000` instead of `http://127.0.0.1:3000`.
101+
102+
**Setup:**
103+
104+
```bash
105+
# 1. Install Localias
106+
brew install peterldowns/tap/localias
107+
108+
# 2. Run setup (requires sudo)
109+
pnpm setup:local
110+
111+
# 3. Start dev server
112+
pnpm dev
113+
```
114+
115+
Visit `https://npmx.test` (localias proxies to `127.0.0.1:3000`).
116+
117+
**Uninstall:**
118+
119+
```bash
120+
pnpm setup:local:uninstall
121+
```
122+
98123
## Development workflow
99124

100125
### Available commands

nuxt.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ export default defineNuxtConfig({
303303
},
304304

305305
vite: {
306+
server: {
307+
// Allow .test domains for local development (e.g., npmx.test via localias)
308+
allowedHosts: ['.test'],
309+
},
306310
optimizeDeps: {
307311
include: [
308312
'@vueuse/core',

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"generate:sprite": "node scripts/generate-file-tree-sprite.ts",
3535
"generate:fixtures": "node scripts/generate-fixtures.ts",
3636
"generate:lexicons": "lex build --lexicons lexicons --out shared/types/lexicons --clear",
37+
"setup:local": "bash scripts/setup-local-domain.sh",
38+
"setup:local:uninstall": "localias rm npmx.test && sudo localias stop || echo 'No local domain configured'",
3739
"test": "vite test",
3840
"test:a11y": "pnpm build:test && LIGHTHOUSE_COLOR_MODE=dark pnpm test:a11y:prebuilt && LIGHTHOUSE_COLOR_MODE=light pnpm test:a11y:prebuilt",
3941
"test:a11y:prebuilt": "./scripts/lighthouse.sh",

scripts/setup-local-domain.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
set -e
3+
4+
R='\033[0;31m' G='\033[0;32m' Y='\033[1;33m' B='\033[0;34m' NC='\033[0m'
5+
6+
error_exit() {
7+
echo -e "\n${R}$1${NC}" >&2
8+
[ -n "$2" ] && echo -e "${Y}$2${NC}" >&2
9+
exit 1
10+
}
11+
12+
# Detect operating system
13+
detect_os() {
14+
case "$(uname -s)" in
15+
Darwin*)
16+
echo "macos"
17+
;;
18+
Linux*)
19+
if grep -qi microsoft /proc/version 2>/dev/null; then
20+
echo "wsl"
21+
else
22+
echo "linux"
23+
fi
24+
;;
25+
MINGW*|MSYS*|CYGWIN*)
26+
echo "windows"
27+
;;
28+
*)
29+
echo "unknown"
30+
;;
31+
esac
32+
}
33+
34+
OS_TYPE=$(detect_os)
35+
36+
echo -e "\n🌐 Configure npmx.test domain for local development"
37+
38+
# Check for unsupported platforms
39+
if [ "$OS_TYPE" = "windows" ]; then
40+
error_exit "Windows is not supported by Localias" \
41+
"Please use WSL2 instead: https://learn.microsoft.com/windows/wsl/install"
42+
fi
43+
44+
if [ "$OS_TYPE" = "unknown" ]; then
45+
error_exit "Unsupported operating system" "Localias supports macOS, Linux, and WSL2"
46+
fi
47+
48+
# Check prerequisites with platform-specific instructions
49+
if ! command -v localias &>/dev/null; then
50+
case "$OS_TYPE" in
51+
macos)
52+
error_exit "Localias not installed" "brew install peterldowns/tap/localias"
53+
;;
54+
linux|wsl)
55+
error_exit "Localias not installed" "go install github.com/peterldowns/localias/cmd/localias@latest"
56+
;;
57+
esac
58+
fi
59+
60+
[ -f ".localias.yml" ] || error_exit ".localias.yml not found" "Run from project root"
61+
62+
# Linux/WSL: Check and configure privileged port capability
63+
if [ "$OS_TYPE" = "linux" ] || [ "$OS_TYPE" = "wsl" ]; then
64+
LOCALIAS_PATH=$(which localias)
65+
if ! getcap "$LOCALIAS_PATH" 2>/dev/null | grep -q "cap_net_bind_service"; then
66+
echo -e "${Y}⚙ Configuring privileged port access for Localias${NC}"
67+
echo "This allows Localias to bind to ports 80 and 443 without sudo"
68+
sudo setcap CAP_NET_BIND_SERVICE=+eip "$LOCALIAS_PATH" || \
69+
error_exit "Failed to set capabilities" "Run: sudo setcap CAP_NET_BIND_SERVICE=+eip \$(which localias)"
70+
echo -e "${G}✓ Capabilities configured${NC}"
71+
fi
72+
fi
73+
74+
# Check if already configured
75+
if localias list 2>/dev/null | grep -q "npmx.test"; then
76+
echo -e "${Y}⚠ npmx.test already configured${NC}"
77+
if localias status &>/dev/null; then
78+
echo -e "${G}✓ Daemon running${NC} - visit ${B}https://npmx.test${NC}"
79+
exit 0
80+
fi
81+
echo "Restarting daemon..."
82+
else
83+
echo "Configuring npmx.test → localhost:3000 (requires sudo)"
84+
read -p "Press Enter to continue or Ctrl+C to cancel... "
85+
localias set npmx.test 3000 || error_exit "Failed to configure alias" "Check sudo access"
86+
fi
87+
88+
# Start daemon
89+
echo "Starting localias daemon (requires sudo)..."
90+
sudo localias stop 2>/dev/null || true
91+
if ! sudo localias start 2>&1 | grep -q "server running"; then
92+
error_exit "Failed to start daemon" "Check ports 80/443 or run: sudo localias start"
93+
fi
94+
95+
# Verify
96+
sleep 1
97+
if ! localias status &>/dev/null; then
98+
error_exit "Daemon not running" "Run manually: sudo localias start"
99+
fi
100+
101+
echo -e "\n${G}✓ Setup complete${NC}"
102+
echo -e " Start dev server: ${B}pnpm dev${NC}"
103+
echo -e " Visit: ${B}https://npmx.test${NC}"
104+
echo -e " Remove: ${B}pnpm setup:local:uninstall${NC}"
105+
106+
# Platform-specific notes
107+
if [ "$OS_TYPE" = "wsl" ]; then
108+
echo -e "\n${Y}ℹ WSL2 Note:${NC}"
109+
echo -e " - SSL certificates work in WSL browsers"
110+
echo -e " - For Windows browsers, manually install cert from:"
111+
echo -e " ~/.localias/certs/npmx.test.crt"
112+
fi
113+
114+
# AtProto OAuth caveat
115+
echo -e "\n${Y}⚠ AtProto OAuth Note:${NC}"
116+
echo -e " When using Bluesky login, the OAuth callback will redirect to"
117+
echo -e " ${B}http://127.0.0.1:3000${NC} instead of ${B}npmx.test${NC}"
118+
echo -e " This is required per AtProto spec for localhost development."
119+
echo -e " Your session will work correctly after the redirect."
120+
echo -e " See: ${B}https://atproto.com/specs/oauth#localhost-client-development${NC}"
121+
122+
echo ""

0 commit comments

Comments
 (0)