Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature base url #351

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/server/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { ConfigService } from '@nestjs/config';
export class AppService {
constructor(private readonly configService: ConfigService) {}
getHello(): string {
const { host, isProd, port, baseUrl } = this.configService.get('server');
return `
<div style="display:flex;justify-content: center;height: 100%;align-items: center;font-size: 30px;">
<div>>> <a href="/dash">WeWe RSS</a> <<</div>
</div>
`;
<div>>> <a href="${baseUrl}dash">WeWe RSS</a> <<</div>
</div>`;
}
}
3 changes: 2 additions & 1 deletion apps/server/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const configuration = () => {
const isProd = process.env.NODE_ENV === 'production';
const port = process.env.PORT || 4000;
const host = process.env.HOST || '0.0.0.0';
const baseUrl = process.env.WEWERSS_BASE_URL || '/';

const maxRequestPerMinute = parseInt(
`${process.env.MAX_REQUEST_PER_MINUTE}|| 60`,
Expand All @@ -19,7 +20,7 @@ const configuration = () => {

const enableCleanHtml = process.env.ENABLE_CLEAN_HTML === 'true';
return {
server: { isProd, port, host },
server: { isProd, port, host, baseUrl },
throttler: { maxRequestPerMinute },
auth: { code: authCode },
platform: { url: platformUrl },
Expand Down
7 changes: 4 additions & 3 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
const configService = app.get(ConfigService);

const { host, isProd, port } =
const { host, isProd, port, baseUrl } =
configService.get<ConfigurationType['server']>('server')!;

const assetsPrefix = `${baseUrl}dash/assets/`;
app.setGlobalPrefix(baseUrl);
app.use(json({ limit: '10mb' }));
app.use(urlencoded({ extended: true, limit: '10mb' }));

app.useStaticAssets(join(__dirname, '..', 'client', 'assets'), {
prefix: '/dash/assets/',
prefix: assetsPrefix,
});
app.setBaseViewsDir(join(__dirname, '..', 'client'));
app.setViewEngine('hbs');
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ThemeProvider from './provider/theme';

function App() {
return (
<BrowserRouter basename="/dash">
<BrowserRouter basename={`${import.meta.env.VITE_WEWERSS_BASE_URL}dash`}>
<ThemeProvider>
<TrpcProvider>
<Routes>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/provider/trpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useState } from 'react';
import { toast } from 'sonner';
import { isTRPCClientError, trpc } from '../utils/trpc';
import { getAuthCode, setAuthCode } from '../utils/auth';
import { enabledAuthCode, serverOriginUrl } from '../utils/env';
import { enabledAuthCode, serverOriginUrl, baseUrl } from '../utils/env';

export const TrpcProvider: React.FC<{ children: React.ReactNode }> = ({
children,
Expand Down Expand Up @@ -81,7 +81,7 @@ export const TrpcProvider: React.FC<{ children: React.ReactNode }> = ({
enabled: () => true,
}),
httpBatchLink({
url: serverOriginUrl + '/trpc',
url: serverOriginUrl + baseUrl + 'trpc',
async headers() {
const token = getAuthCode();

Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export const appVersion = __APP_VERSION__;

export const enabledAuthCode =
window.__WEWE_RSS_ENABLED_AUTH_CODE__ === false ? false : true;

export const baseUrl = import.meta.env.VITE_WEWERSS_BASE_URL || '/';
6 changes: 3 additions & 3 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { readFileSync } from 'fs';

const projectRootDir = resolve(__dirname);

const isProd = process.env.NODE_ENV === 'production';

const baseUrl = loadEnv('mode', process.cwd()).VITE_WEWERSS_BASE_URL || '/';
console.log('process.env.NODE_ENV: ', process.env.NODE_ENV);

const packageJson = JSON.parse(
Expand All @@ -15,7 +15,7 @@ const packageJson = JSON.parse(

// https://vitejs.dev/config/
export default defineConfig({
base: '/dash',
base: `${baseUrl}dash`,
define: {
__APP_VERSION__: JSON.stringify(packageJson.version),
},
Expand Down