Skip to content

Commit ab73f60

Browse files
committed
Got sub-path hosting working
Required monkey-patching URL object in JS to workaround possible inertiaJS limitations.
1 parent 1dd49b6 commit ab73f60

File tree

10 files changed

+44
-13
lines changed

10 files changed

+44
-13
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ APP_LOAD_POST_THUMBNAILS=true
155155
APP_FEED_UPDATE_FREQUENCY=60
156156
```
157157

158+
## Usage Behind a Reverse Proxy
159+
160+
When using behind a reverse proxy, ensure common forwarding headers are set so that the application can properly detect the right host and path to use.
161+
The below shows a sub-path proxy config location block for nginx. Note the `X-Forwarded-Prefix` header to make the application aware of sub-path usage.
162+
163+
```nginx
164+
location /rss/ {
165+
proxy_pass http://container-ip:80/;
166+
proxy_set_header Host $host;
167+
proxy_set_header X-Real-IP $remote_addr;
168+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
169+
proxy_set_header X-Forwarded-Proto $scheme;
170+
proxy_set_header X-Forwarded-Host $host;
171+
proxy_set_header X-Forwarded-Port $server_port;
172+
proxy_set_header X-Forwarded-Prefix "/rss/";
173+
proxy_redirect off;
174+
}
175+
```
176+
158177
## Manual Install
159178

160179
Manually installing the application is not recommended unless you are performing development work on the project.

app/Http/Middleware/TrustProxies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class TrustProxies extends Middleware
1212
*
1313
* @var array<int, string>|string|null
1414
*/
15-
protected $proxies;
15+
protected $proxies = '*';
1616

1717
/**
1818
* The headers that should be used to detect proxies.

config/app.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@
9595
|
9696
*/
9797

98-
'url' => env('APP_URL', 'http://localhost'),
99-
100-
'asset_url' => env('ASSET_URL'),
98+
'url' => '',
99+
'asset_url' => '',
101100

102101
/*
103102
|--------------------------------------------------------------------------

docker/.env.container

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ APP_NAME=RSS
22
APP_ENV=production
33
APP_KEY=
44
APP_DEBUG=false
5-
# APP_URL=http://localhost
65

76
# Path to configuration
87
APP_CONFIG_FILE=/app/storage/feeds.txt

resources/js/Pages/Posts.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<div class="md:max-w-xs w-full hidden md:block" :class="{'!block': mobileShowOptions}">
1414

1515
<div v-if="search || tag || feed || page !== 1" class="mb-8">
16-
<Link href="/" class="font-bold text-black dark:text-gray-400">&laquo; Back to home</Link>
16+
<Link href="./" class="font-bold text-black dark:text-gray-400">&laquo; Back to home</Link>
1717
</div>
1818

1919
<div class="mb-8">
@@ -50,7 +50,7 @@
5050

5151
<div class="flex items-center justify-between mb-2">
5252
<h2 class="font-bold text-black dark:text-gray-400">
53-
<Link href="/">Posts</Link>
53+
<Link href="./">Posts</Link>
5454
<span v-if="tag"> / #{{ tag }}</span>
5555
<span v-if="feed && feeds.length === 1"> / <span :style="{ color: feeds[0].color}">{{ feeds[0].name }}</span></span>
5656
<span v-if="search"> ?= {{ search }}</span>

resources/js/Parts/Feed.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="py-1 my-2">
33
<h4 class="font-bold text-black dark:text-gray-400" :style="{color: feed.color}">
4-
<Link :href="`/f/${encodeURIComponent(encodeURIComponent(feed.url))}`">{{ feed.name }}</Link>
4+
<Link :href="`f/${encodeURIComponent(encodeURIComponent(feed.url))}`">{{ feed.name }}</Link>
55
</h4>
66
<div class="font-mono text-gray-600 dark:text-gray-500 text-xs my-1 overflow-ellipsis whitespace-nowrap w-full overflow-hidden">{{ feed.url }}</div>
77
<div class="flex gap-1 text-gray-600 dark:text-gray-500 text-sm flex-wrap">
@@ -44,7 +44,7 @@ export default {
4444
window.location.reload();
4545
},
4646
async pollFeedStatus() {
47-
const resp = await axios.get(`/feed`, {params: {url: this.feed.url}});
47+
const resp = await axios.get(`feed`, {params: {url: this.feed.url}});
4848
if (resp?.data?.outdated) {
4949
this.reloadingPoll = setTimeout(this.pollFeedStatus.bind(this), 3000);
5050
} else {

resources/js/Parts/Post.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
dark:hover:border-gray-700 dark:hover:bg-gray-800 rounded hover:relative hover:z-20 -my-px">
66

77
<div class="flex text-sm text-gray-600 dark:text-gray-400 items-center flex-wrap">
8-
<Link :href="`/f/${encodeURIComponent(encodeURIComponent(post.feed.url))}`" :style="{color: post.feed.color}" class="font-bold text-xs block">{{ post.feed.name }}</Link>
8+
<Link :href="`f/${encodeURIComponent(encodeURIComponent(post.feed.url))}`" :style="{color: post.feed.color}" class="font-bold text-xs block">{{ post.feed.name }}</Link>
99
<div class="px-2">&bull;</div>
1010
<div class="italic" :title="isoTime">About {{ relatedPublishedTime }} ago</div>
1111
<div class="px-2 hidden md:block">&bull;</div>
@@ -17,7 +17,7 @@
1717
<div :class="{'flex items-center gap-5': formatList && post.thumbnail}">
1818
<div v-if="post.thumbnail && !formatCompact" :class="{'w-32': formatList}">
1919
<a :href="post.url" target="_blank" class="block overflow-hidden rounded my-2 border dark:border-black">
20-
<img :src="`/storage/${post.thumbnail}`"
20+
<img :src="`storage/${post.thumbnail}`"
2121
loading="lazy"
2222
class="w-full h-32 md:h-48 lg:h-64 object-cover saturate-50"
2323
:class="{'h-16 md:h-16 lg:h-16': formatList}"

resources/js/Parts/Tag.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<Link :href="`/t/${urlTag}`"
2+
<Link :href="`t/${urlTag}`"
33
class="inline-block">{{ tag }}</Link>
44
</template>
55

resources/js/app.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import { createApp, h } from 'vue'
22
import { createInertiaApp, Link } from '@inertiajs/inertia-vue3'
33
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
44

5+
// Monkey-Patching of 'URL' constructor to use URL set via the `<base>` tag since
6+
// inertia.js does not seem to have a dynamic way to set a base URL or use base tags.
7+
(function(nativeURL) {
8+
const configuredBase = document.querySelector('base').href;
9+
window.URL = function(url, base) {
10+
if (base === window.location.toString()) {
11+
base = configuredBase;
12+
}
13+
return new nativeURL(url, base);
14+
}
15+
})(URL);
16+
517
createInertiaApp({
618
resolve: name => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
719
setup({ el, App, props, plugin }) {
@@ -10,4 +22,4 @@ createInertiaApp({
1022
.use(plugin)
1123
.mount(el)
1224
},
13-
})
25+
});

resources/views/app.blade.php

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

77
<title>{{ config('app.name') }}</title>
88

9+
<base href="{{ asset('') }}">
10+
911
@if(!app()->runningUnitTests())
1012
@vite(['resources/css/app.css', 'resources/js/app.js'])
1113
@endif

0 commit comments

Comments
 (0)