ES6 - Express4:无论如何要在localhost上显示favicon?

时间:2017-01-27 07:30:20

标签: node.js express typescript ecmascript-6

使用 serve-favicon (v2.3.2)/ 节点 (v7.4.0)/ 表达 (v4.14.0)与 Typescript (v2.1.5)和ES6,我试图获得一个favicon通常:

在我的 server.ts

import * as favicon from "serve-favicon";
...
export class Server {
    public app: express.Application;
    public static bootstrap(): Server {...}
    constructor() {...}
    public config() {
         this.app.use(express.static(path.join(__dirname, "public")));
         ...
         this.app.use(favicon(path.join(__dirname, "public", "favicon.ico")));
         ...
    }
    private routes {...}
 }

我插入了myapp / public / favicon.ico图片,localhost上没有显示任何内容:8080,无论如何要显示它?

更新 即可。将TS转换为JS后的app目录结构

  dist
    app
      |_ interfaces  (...)
      |_ models  (...)
      |_ public
      |    |_ favicon.ico
      |
      |_ routes (...)
      |_ schemas. (...)
      |_ test  (...)
      |_ views  (...)
      |_ route.js
      |_ server.js

0 个答案:

没有答案