javascript - 使用 expressjs 提供静态文件
问题描述
这是我的代码:
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>
解决方案
推荐阅读
- powershell - Powershell 脚本无法识别查询参数
- java - Maven 未使用 Java 11 - 编译致命错误:目标版本无效:11
- docker - 如何在 dockerfile 中传递 url 链接以根据 url 参数创建不同的容器
- woocommerce - WooCommerce REST API 错误 401 - “woocommerce_rest_cannot_view”
- mysql - Laravel 与 docker 数据库错误:SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not resolve
- reactjs - 当父组件和子组件都是功能组件时如何使用引用?
- vscode-extensions - 如何根据特殊的开始和结束词添加缩进策略?
- naming-conventions - 如何处理骆驼案中的几个数字?
- linux - 我想使用 shell 将数据放入一个新文件中
- javascript - 有没有机会在代理中获得外部范围?