javascript - 我怎样才能让 express.static() 函数最后忽略“/”?
问题描述
我正在制作一个服务器,用于呈现一个 html 页面
onst express = require('express');
const server = express();
const path = require('path');
//const WebSocket = require('ws');
const port = 8088;
server.use(express.static(path.join(__dirname, 'static')));
server.set('view engine',"ejs");
server.get('/emulator',(req,res)=> {
console.log(req.url);
res.render('app');
res.end();
})
当我发送这个请求时它工作 http://localhost:8088/emulator 但是当我像这样 http://localhost:8088/emulator/ 最后添加“/”时,只有 html 页面出现,没有 css,js 这如何我在 html 页面中调用静态文件
<link rel="stylesheet" href="css/style.css">
<script src="js/main.js"></script>
解决方案
推荐阅读
- python - 我的等待文件出现在目录中的 Python 脚本在验证此存在的级别迭代太多
- rust - 在 Rust 中左移 (<<) 时如何惯用地测试溢出?
- c++ - C++ 应用程序在 int main() 之前意外崩溃,访问读取冲突
- http - 没有为具有空/无负载的 PATCH 请求设置 Content-Length 标头 - GoLang
- kubeadm - KubeletExtraArgs 在 GO NodeRegistrationOptions 对象中支持的所有参数是什么?
- javascript - 将自定义组件呈现为列表项
- mysql - 由于小的 innodb_buffer_pool_size MySQL 返回错误结果而没有任何警告
- node.js - 通过 npm 安装 vue/cli 时出现 JSON 错误
- java - 使用参数从 Runnable 更新 UI
- python - Beautifulsoup 如何从特定类中提取文本