【发布时间】:2021-12-10 13:38:11
【问题描述】:
我有一个与 Ts.ED 一起开发的 SPA,但由于我不知道发生了什么变化,我完全停止了提供静态内容。我尽可能地减少了代码,甚至制作了一个展示库。
问题似乎是静态路由没有挂载。我什至开始调试 Ts.ED 代码,我不知道出了什么问题。我将提供主要代码、消息和用于复制的 git 存储库。
公平地说,当我开发完全不同的东西时,它运行得非常好,以至于我不明白会发生什么。
server/index.ts
import { join } from "path";
import { $log, Configuration, Inject, PlatformApplication, Res } from "@tsed/common";
import { PlatformExpress } from "@tsed/platform-express";
import config from '@config';
const rootDir = __dirname;
const clientDir = join(rootDir, '../client');
console.log('clientDir: ' + clientDir);
@Configuration({
rootDir,
port: config.http.port,
statics: {"/": [{root: clientDir}]}
})
export class Server {}
async function bootstrap() {
try {
$log.debug("Start server...");
const platform = await PlatformExpress.bootstrap(Server, {});
await platform.listen();
$log.debug("Server initialized");
} catch (er) {
$log.error(er);
}
}
bootstrap();
调试日志
[2021-10-25T02:39:50.500] [INFO ] [TSED] - Call hook $afterRoutesInit
[2021-10-25T02:39:50.501] [INFO ] [TSED] - Routes mounted :
[2021-10-25T02:39:50.502] [INFO ] [TSED] -
┌────────┬──────────┬──────────────┐
加载index.html时出错
error: {
name: 'NOT_FOUND',
message: 'Resource "/index.html" not found',
status: 404,
errors: [],
stack: 'NOT_FOUND: Resource "/index.html" not found\n' +
' at PlatformExceptions.resourceNotFound (C:\\dev\\fsd-merde\\node_modules\\@tsed\\platform-exceptions\\lib\\index.js:233:23)\n' +
' at C:\\dev\\fsd-merde\\node_modules\\@tsed\\platform-express\\lib\\components\\PlatformExpress.js:39:128\n' +
' at Layer.handle [as handle_request] (C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\layer.js:95:5)\n' +
' at trim_prefix (C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\index.js:317:13)\n' +
' at C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\index.js:284:7\n' +
' at Function.process_params (C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\index.js:335:12)\n' +
' at next (C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\index.js:275:10)\n' +
' at PlatformExpressHandler.next (C:\\dev\\fsd-merde\\node_modules\\@tsed\\common\\lib\\index.js:1077:47)\n' +
' at PlatformExpressHandler.onSuccess (C:\\dev\\fsd-merde\\node_modules\\@tsed\\common\\lib\\index.js:1017:17)\n' +
' at C:\\dev\\fsd-merde\\node_modules\\@tsed\\common\\lib\\index.js:947:29\n' +
' at processTicksAndRejections (node:internal/process/task_queues:96:5)'
},
stack: 'NOT_FOUND: Resource "/index.html" not found\n' +
' at PlatformExceptions.resourceNotFound (C:\\dev\\fsd-merde\\node_modules\\@tsed\\platform-exceptions\\lib\\index.js:233:23)\n' +
' at C:\\dev\\fsd-merde\\node_modules\\@tsed\\platform-express\\lib\\components\\PlatformExpress.js:39:128\n' +
' at Layer.handle [as handle_request] (C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\layer.js:95:5)\n' +
' at trim_prefix (C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\index.js:317:13)\n' +
' at C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\index.js:284:7\n' +
' at Function.process_params (C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\index.js:335:12)\n' +
' at next (C:\\dev\\fsd-merde\\node_modules\\express\\lib\\router\\index.js:275:10)\n' +
' at PlatformExpressHandler.next (C:\\dev\\fsd-merde\\node_modules\\@tsed\\common\\lib\\index.js:1077:47)\n' +
' at PlatformExpressHandler.onSuccess (C:\\dev\\fsd-merde\\node_modules\\@tsed\\common\\lib\\index.js:1017:17)\n' +
' at C:\\dev\\fsd-merde\\node_modules\\@tsed\\common\\lib\\index.js:947:29\n' +
' at processTicksAndRejections (node:internal/process/task_queues:96:5)'
}
【问题讨论】:
-
我什至把它作为一个问题提交了,我希望它不是在第 310197 行缺少分号 - github.com/tsedio/tsed/issues/1600