Ts.ED simple static server surprise 404 failure

142 views Asked by At

I have a SPA who I was developing with Ts.ED and, with I don't know what change, completely stopped serving the static content. I reduced as much as possible the code to even make an exposition repository.

The problem seems that the static routes are not mounted. I even begun to debug Ts.ED code, I have no clue of what went wrong. I'll provide with the main code, the messages, and a git repo for reproduction.

To be fair, it was working so well while I was developing something completely different, that I don't understand what might have happened.

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();

Debug log

[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] - 
┌────────┬──────────┬──────────────┐

Error when loading 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)'
}

Here is a repository

1

There are 1 answers

1
eddow On

Finally, it was not a wrong manipulation of mine but a bug who didn't reveal before and was solved (now in version 6.75.7) - So, the solution was ... to update.