mirror of
https://github.com/xxnuo/MTranServer.git
synced 2026-06-07 16:52:00 +08:00
fix: urls
This commit is contained in:
@@ -15,13 +15,9 @@ const mimeTypes: Record<string, string> = {
|
||||
'.ico': 'image/x-icon',
|
||||
};
|
||||
|
||||
export const UI: RequestHandler = async (req: Request, res: Response, next: NextFunction) => {
|
||||
export const uiStatic: RequestHandler = async (req: Request, res: Response, next: NextFunction) => {
|
||||
let filePath = req.path;
|
||||
|
||||
if (filePath.startsWith('/ui/')) {
|
||||
filePath = filePath.substring(3);
|
||||
}
|
||||
|
||||
if (filePath === '/' || filePath === '') {
|
||||
filePath = '/index.html';
|
||||
}
|
||||
@@ -31,7 +27,6 @@ export const UI: RequestHandler = async (req: Request, res: Response, next: Next
|
||||
if (assetPath) {
|
||||
const ext = filePath.substring(filePath.lastIndexOf('.'));
|
||||
const mimeType = mimeTypes[ext] || 'application/octet-stream';
|
||||
|
||||
res.setHeader('Content-Type', mimeType);
|
||||
const buffer = await readFile(assetPath);
|
||||
res.send(buffer);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import express from 'express';
|
||||
import express, { Request, Response, NextFunction } from 'express';
|
||||
import fs from 'fs/promises';
|
||||
import swaggerUi from 'swagger-ui-express';
|
||||
import { getConfig } from '@/config/index.js';
|
||||
@@ -9,7 +9,7 @@ import { cleanupLegacyBin } from '@/assets/index.js';
|
||||
import { requestId, errorHandler, cors } from '@/middleware/index.js';
|
||||
import { RegisterRoutes } from '@/generated/routes.js';
|
||||
import swaggerDocument from '@/generated/swagger.json';
|
||||
import { UI } from '@/middleware/ui.js';
|
||||
import { uiStatic } from '@/middleware/ui.js';
|
||||
import { swaggerStatic } from '@/middleware/swagger.js';
|
||||
|
||||
export async function run() {
|
||||
@@ -33,15 +33,29 @@ export async function run() {
|
||||
|
||||
RegisterRoutes(app);
|
||||
|
||||
app.use('/docs', swaggerStatic, swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||
app.use('/ui', (req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.originalUrl === '/ui') {
|
||||
return res.redirect(301, '/ui/');
|
||||
}
|
||||
next();
|
||||
}, uiStatic);
|
||||
|
||||
app.use(UI);
|
||||
app.use('/docs', (req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.originalUrl === '/docs') {
|
||||
return res.redirect(301, '/docs/');
|
||||
}
|
||||
next();
|
||||
}, swaggerStatic, swaggerUi.serve, swaggerUi.setup(swaggerDocument));
|
||||
|
||||
app.get('/', (_, res) => res.redirect(301, '/ui/'));
|
||||
|
||||
app.use((_, res) => res.status(404).send('404'));
|
||||
|
||||
app.use(errorHandler());
|
||||
|
||||
const server = app.listen(parseInt(config.port), config.host, () => {
|
||||
logger.important(`HTTP Service URL: http://${config.host}:${config.port}`);
|
||||
logger.important(`Swagger Docs: http://${config.host}:${config.port}/docs`);
|
||||
logger.important(`Web UI: http://${config.host}:${config.port}/ui/`);
|
||||
logger.important(`Swagger Docs: http://${config.host}:${config.port}/docs/`);
|
||||
logger.important(`Log level set to: ${config.logLevel}`);
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import path from "path"
|
||||
import tailwindcss from "@tailwindcss/vite"
|
||||
|
||||
export default defineConfig({
|
||||
base: '/',
|
||||
base: '/ui/',
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
Reference in New Issue
Block a user