[英]How to call files from a page in nodeJS
I'm running a nodeJS server with the following structure: 我正在运行具有以下结构的nodeJS服务器:
├── init.js
├── Integration
│ └── [libraries and stuff]
├── package.json
└── views
├── 3Dmodel.html
├── 404.html
├── index.html
└── models
└── damaliscus_korrigum.ply
In init.js
(file launched to launch the server) I have: 在
init.js
(启动文件以启动服务器)中,我有:
createServer: function(){
var express = require("express");
var app = express();
var http = require('http');
var server = http.createServer(app);
var router = express.Router();
var path = __dirname + '/views/';
app.use(favicon(__dirname + '/images/logo.png'));
router.use(function (req,res,next) {
console.log("/" + req.method);
next();
});
router.get("/",function(req,res){
res.sendFile(path + "index.html");
});
router.get("/3Dmodel",function(req,res){
res.sendFile(path + "3Dmodel.html");
}); //same for all pages
}
I want to call the file /views/models/damaliscus_korrigum.ply
in /views/3Dmodel.html
here: 我想在
/views/3Dmodel.html
中将文件/views/models/damaliscus_korrigum.ply
/views/3Dmodel.html
:
var loader = new THREE.PLYLoader();
loader.load( 'damaliscus_korrigum.ply', function ( geometry ) { ... }
but what path should I use to call it? 但是我应该用什么路径来称呼它?
/models/damaliscus_korrigum.ply
hasn't worked, nor has models/damaliscus_korrigum.ply
or ./models/damaliscus_korrigum.ply
. /models/damaliscus_korrigum.ply
无效,也不具有models/damaliscus_korrigum.ply
或./models/damaliscus_korrigum.ply
。
First of all you have to serve the models from your server (so that the client can request it), for serving a static directory Express.static
is a good choice: 首先,必须从服务器提供模型(以便客户端可以请求模型),以便为静态目录提供服务
Express.static
是一个不错的选择:
app.use("/models/", express.static(path + "/models/"));
Now your client can send requests that get answered. 现在,您的客户可以发送得到答复的请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.