Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Vue资源可以';t加载快速静态文件_Javascript_Node.js_Express_Vuejs2_Vue Resource - Fatal编程技术网

Javascript Vue资源可以';t加载快速静态文件

Javascript Vue资源可以';t加载快速静态文件,javascript,node.js,express,vuejs2,vue-resource,Javascript,Node.js,Express,Vuejs2,Vue Resource,所以,我有点问题。这是我的server.js require('dotenv').load(); const http = require('http'); const path = require('path'); const express = require('express'); const app = express(); const server = http.createServer(app).listen(8080, () => { console.log(

所以,我有点问题。这是我的server.js

require('dotenv').load();
const http = require('http');
const path = require('path');
const express = require('express');

const app = express();



const server = http.createServer(app).listen(8080, () => {
    console.log('Foliage started on port 8080');
});

app.use(express.static(path.join(__dirname, '/public')));

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, 'index.html'));
});

app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, 'index.html'));
});
这样做的目的是,对于每个
/无论什么
,它都会给出
index.html
文件。除此之外,它还提供来自
/public
的静态文件。现在,my index.html如下所示:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Foliage</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="css/foliage.css" media="screen" title="no title">
        <script src="https://use.fontawesome.com/763cbc8ede.js"></script>
    </head>
    <body>
        <div id="app">
            <router-view :key="$router.currentRoute.path"></router-view>
        </div>
        <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
        <script src="js/md5.js"></script>
        <script src="js/cookies.js"></script>
        <script src="js/dragula.js"></script>
        <script src="js/build.js"></script>

    </body>
</html>
但是,此请求没有提供
public/themes/barning/templates
中的文件。相反,它会返回站点自己的index.html文件。我怎样才能解决这个问题

app.use(express.static(path.join(uu dirname,“/public”))

应用程序获取(“/”,(请求,请求)=>{ res.sendFile(path.join(uu dirname,'index.html');})

应用程序获取(“*”,(请求,请求)=>{ res.sendFile(path.join(uu dirname,'index.html');})

尝试console.log(path.join(\uu dirname,/public'))和console.log(path.join(\uu dirname,'index.html')以查看路径是否符合您的期望

这个.http.get('themes/barning/templates/'+page.Template+'.html')。然后((响应) => { console.log(response.body);})


您也可以尝试将get请求记录到控制台中。通常我需要使用路径来确保提供的文件正确。

您可以尝试的一件事是定义一个
get
路由,该路由在底部的通配符之前使用您的模板进行响应

app.get('/themes', (req, res) => {
  // get the theme name
  res.sendFile(path.join(__dirname, ... ));
});

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/themes', (req, res) => {
  // get the theme name
  res.sendFile(path.join(__dirname, ... ));
});

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
});