Javascript-форум (https://javascript.ru/forum/)
-   Node.JS (https://javascript.ru/forum/node-js-io-js/)
-   -   express app.sendFile('index.html') не удается получить связанные файлы. (https://javascript.ru/forum/node-js-io-js/69620-express-app-sendfile-%27index-html%27-ne-udaetsya-poluchit-svyazannye-fajjly.html)

Astrey 06.07.2017 17:02

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

destus 06.07.2017 17:25

http://expressjs.com/ru/starter/static-files.html


Часовой пояс GMT +3, время: 05:34.