我有一个Server类: Server.js
const charSchema = new Schema({
id: String,
name: [String],
age: [String],
我在app.js中启动服务器:
const express = require('express');
class Server {
constructor() {
this.app = express();
this.app.get('/', function(req, res) {
res.send('Hello World');
})
}
start() {
this.app.listen(8080, function() {
console.log('MPS application is listening on port 8080 !')
});
}
}
module.exports = Server;
我的html代码: index.html
const Server = require('./server/Server');
const express = require('express');
const server = new Server();
server.start();
server.app.use('/client', express.static(__dirname + '/client'));
我的index.js:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<title></title>
</head>
<body>
<div id="historique">
<button v-on:click="openHistorique">
Historique Proface
</button>
</div>
</body>
</html>
文件夹结构:
window.onload = function () {
var hist = new Vue({
el:'#historique',
methods: {
openHistorique: function() {
console.log("On clique");
document.location.href="../AffichageHistorique/index.php";
}
}
})
}
当我单击index.html中的按钮时,我想打开index.php,但出现错误client
AffichageHistorique
index.php
js
index.js
index.html
server
Server.js
app.js
,但看不到如何解决该问题。
答案 0 :(得分:1)
这里:
this.app.get('/', function(req, res) {
…您编写了一个处理程序,用于处理客户端尝试获取/
时发生的情况。
您还没有为/AffichageHistorique/index.php
写一个。
server.app.use('/client', express.static(__dirname + '/client'));
…接近,但由于您的URL并非以/client
开头,因此不会被点击。
即使这样做,也不会执行 PHP。
静态模块用于提供静态文件,而不用于执行PHP。
如果您使用的是PHP,则可以考虑使用设计用于PHP的服务器(例如Apache HTTPD或Lighttpd)。