gpt4 book ai didi

node.js - 为什么我的 Logo 不显示 nodejs 应用程序

转载 作者:搜寻专家 更新时间:2023-10-31 23:50:38 26 4
gpt4 key购买 nike

这是我的项目目录的图片。

enter image description here

我在 template/assets/logo.png 中有我的标志。

在我的 server.ts 文件中,我将中间件 express 用作 app.use( express.static( "template") );

不幸的是,当我尝试在我的 html 文件中显示 Logo 时,它没有显示。

 <img src="assets/logo.png" alt="Logo">

这是我的 server.ts 文件:

// Import everything from express and assign it to the express variable
import express from 'express';
import fs from 'fs';
// Import WelcomeController from controllers entry point
import {WelcomeController} from './app/controllers';

// Create a new express application instance
const app: express.Application = express();



// The port the express app will listen on
const port: any = process.env.PORT || 3000;

// Template folder
app.use( express.static( "template" ) );

// Mount the WelcomeController at the /welcome route
app.use('/', WelcomeController);


// Serve the application at the given port
app.listen(port, () => {

const source = fs.createReadStream('/src/app');
const dest = fs.createWriteStream('/dist');


source.pipe(dest);
source.on('end', function() { /* copied */ });
source.on('error', function(err) { /* error */ });
// Success callback
console.log(`Listening at http://localhost:${port}/`);
});

显示文件的模板的显示方式是什么?

最佳答案

我做错了 app.use( express.static( "template") );

我应该做 app.use(express.static(__dirname + '/app/template'));

关于node.js - 为什么我的 Logo 不显示 nodejs 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51103631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com