Vue-resource에서 Express 정적 파일을 로드할 수 없음
그래서, 나는 약간의 문제가 있다.여기 내 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'));
});
이게 하는 일은, 모든 사람을 위한 것이다./whatever
그것은 더 이상 할 수 없다index.html
그것과 함께, 그것은 정적 파일들을 제공한다./public
이제 내 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>
모든 JS 파일과 스타일 파일이 다음에서 적절하게 로드됨public/js
그리고public/css
이것 때문에그러나, inbuild.js
웹 팩으로 된 vuejs 앱으로, 나는 vue-resource를 사용하여 다른 파일을 로딩한다.public/themes/Bareren/templates
이렇게 생겼는데.
page = {};
page.Template = "Index";
this.$http.get('themes/Barren/templates/'+page.Template+'.html').then((response) => {
console.log(response.body);
});
그러나, 이 요청은 나에게 파일을 제공하지 않는다.public/themes/Barren/templates
. 대신 사이트 자체 인덱스.html 파일을 다시 제공한다.내가 어떻게 이걸 고칠 수 있을까?
app.use(path.path.patic(_path.path.propertic)(_path.path(_pathname, '
app.get(/)', (req, res) => {res.sendFile(path.join(_dirname, 'index.html'); };
app.get(*), (req, res) => {res.sendFile(path.join(_dirname, 'index.html'); };
console.log(path.join(_dirname, '/public') 및 console.log(path.join(_dirname, 'index.html')를 사용하여 경로가 예상 경로와 일치하는지 확인하십시오.
이 달러화get('테마/배런/템플릿/'+페이지)Template+'html').그러면(응답) => {console.log(response.body); };
또한 콘솔에서 가져오기 요청을 로깅해 보십시오.보통은 내가 정확한 파일을 제공하는지 확인하기 위해 두드리는 것을 가지고 놀아야 한다.
한 가지 시도할 수 있는 것은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'));
});
참조URL: https://stackoverflow.com/questions/41439518/vue-resource-cant-load-express-static-file
'IT이야기' 카테고리의 다른 글
Vuejs + 웹 팩: npm 실행 빌드 느림 (0) | 2022.04.21 |
---|---|
v-for를 사용하여 vue.js를 사용하여 테이블을 렌더링하는 방법 (0) | 2022.04.21 |
github/gitlab 페이지가 있는 vuejs 기록 모드 (0) | 2022.04.21 |
FreeMarker 템플릿에 변수가 있는지 확인하는 방법 (0) | 2022.04.21 |
MPI 통신에 MPI_B캐스트 사용 (0) | 2022.04.19 |