使用 expressjs 提供静态文件

时间:2021-07-06 12:53:58

标签: javascript node.js express http-post middleware

这是我的代码

I want to hide my folder from client and put alias before file name

const express = require('express');
const path = require('path');
const app = express();
app.use('/public',express.static(path.join(__dirname,'static')));
app.get('/',(req,res)=> {
    res.sendFile(path.join(__dirname,'static','index.html'));
}).listen(3000);

在 chrome 上检查时,它应该给出:

<link rel='stylesheet' href='/public/css/main.css'>
<script src='/public/js/example.js'></script>

But it is giving me:

   <link rel='stylesheet' href='main.css'>
   <script src='example.js'></script>

0 个答案:

没有答案