express app.sendFile('index.html') не удается получить связанные файлы.
Вложений: 1
Всем привет. Начал изучать node.js и решил воспользваться express framework для маршрутизации. Проблема в том что когда в ответ на запрос я возвращаю файл:
app.get('/', function (req, res) {
console.log('index');
res.sendFile(path.join(__dirname + '/viwes/html/index.html'));
});
Скрипты из файла индекс блокируются браузером firefox и chrome: The resource from “http://localhost:3000/js/app.js” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff). Подскажите, пожалуйста, как правильно возвращать html в ответ на запрос и избавится от ошибки. server.js
var express = require('express');
var path = require('path');
var app = express();
app.all('/', function (req, res, next) {
console.log('Accessing the secret section ...');
next(); // pass control to the next handler
});
// GET method route
app.get('/', function (req, res) {
console.log('index');
res.sendFile(path.join(__dirname + '/viwes/html/index.html'));
});
// POST method route
app.post('/', function (req, res) {
res.send('POST request to the homepage');
});
app.listen(3000);
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
<script src="../js/app.js"></script>
</head>
<body>
<p>Привет!</p>
</body>
</html>
Вложение 3566 |
|
| Часовой пояс GMT +3, время: 17:54. |