[英]MIME type ('text/html') is not a supported
Here are some lines of code... I have another application running that is setup exactly the same and I am having no issues. 这是一些代码行...我正在运行另一个应用程序,该应用程序的设置完全相同,并且没有问题。
app.use('/app', express.static(__dirname + "/public"));
Here is the link tag 这是链接标签
<link rel="stylesheet" type="text/css" href="/app/css/app.css">
It does the same with this img tag 此img标签的功能相同
<img src="/app/img/SCS-NewLogo_donl.svg" height="65px" width="350px" id="sc-logo">
I am not sure why, but it seems to be sending the file as HTML. 我不知道为什么,但是似乎是以HTML格式发送文件。 Usually this means the file is not found on the server, but I checked myself and confirmed that it is. 通常,这意味着在服务器上找不到该文件,但是我检查了一下并确认是该文件。
Full file 完整档案
const express = require('express');
const config = require('./lib/config');
const bodyParser = require('body-parser');
const URLS = require('./lib/URLS.js');
const PORT = process.env.PORT || 9005;
const ENV = config.ENV || 'TEST';
const SERVER = config.SERVER;
const app = express();
app.set('views', './views');
app.set('view engine', 'ejs');
app.use('/app', express.static(__dirname + "/public"));
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.all(/^\/apps$/, function (req, res) {
res.redirect('/apps/job-search');
});
app.get('/apps/job-search', (req, res) => {
res.render('pages/search');
});
app.post('/apps/job-search/send-input', (req, res) => {
// Send data to API server which will handle DB query...
axios.get(URLS.GatherSearchResults)
.then(resp => {
console.log(resp.data);
}).catch(err => {
console.log(err)
});
});
app.listen(PORT, () => {
console.log('App is listening on port ' + PORT + ' on server ' + SERVER + '...');
});
Directory Structure 目录结构
Root
public
css
img
views
pages
search.ejs
partials
header.ejs
footer.ejs
app.js
I thinkk I see your issue. 我想我看到你的问题。 After declaring the route /app
as static, you remap it to '/apps/job-search'
several lines later. 在将路由/app
声明为静态后,您可以在几行后将其重新映射到'/apps/job-search'
。
Change the static line to app.use('/', express.static(__dirname + "/public"));
将静态行更改为app.use('/', express.static(__dirname + "/public"));
and your links in the HTML file should start wit /css
and /img
etc. 并且您在HTML文件中的链接应以/css
和/img
等开头。
Verify that by trying to open one of your existing links, and seeing what content you're currently serving (my guess - it'd be whatever is at '/apps/job-search'
). 通过尝试打开您现有的链接之一,并查看您当前正在提供的内容来进行验证(我想,这将是'/apps/job-search'
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.