我是开发人员的初学者,所以,如果我做错了,我很抱歉,请告诉我如何解决,请...
我在.html
文件中创建了一些功能,仅用于测试,工作。
但是,我看到了EJS模块的示例,我可以尝试使用它们来保证安全性。
并且,我使用所有代码.ejs
文件创建其他存档.html
,但是,不能正常工作,控制台中的错误是:
我的代码使用jQuery
以及这些控制台错误中显示的.js
粘贴内的一些归档/public
我的旧 html
档案
<html>
<head>
<script src="jquery-3.1.1.js"></script>
<script src="app.js"></script>
<base href="/">
<title>XXXXXXXXXXXXXXXX</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta ------ />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="css/app.css">
</head>
<body>
<div id="view-change-button" class="button" onclick="Payloadxxxxxxx.togglePanel(event, this)">
<img class="option full" src="../img/Chat Button.png">
<img class="option not-full" src="../img/Code Button.png">
</div>
<div id="contentParent" class="responsive-columns-wrapper">
<div id="chat-column-holder" class="responsive-column content-column">
<div class="chat-column">
<div id="scrollingChat"></div>
<label for="textInput" class="inputOutline">
<input id="textInput" class="input responsive-column"
placeholder="Digite algo" type="text"
onkeydown="xxxxxxxxxxxxxxxxPanel.inputKeyDown(event, this)">
</label>
</div>
</div>
<div id="payload-column" class="fixed-column content-column">
<div id="payload-initial-message">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxOtherDescription.
</div>
<div id="payload-request" class="payload"></div>
<div id="payload-response" class="payload"></div>
</div>
</div>
我的新 EJS
文件 HTML
和功能代码:
<html>
<head>
<script src="jquery-3.1.1.js"></script>
<script src="app.js"></script>
<base href="/">
<title>XXXXXXXXXXXXXXXX</title>
<meta ------ />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="css/app.css">
</head>
<body>
<div id="view-change-button" class="button" onclick="Payloadxxxxxxx.togglePanel(event, this)">
<img class="option full" src="../img/Chat Button.png">
<img class="option not-full" src="../img/Code Button.png">
</div>
<div id="contentParent" class="responsive-columns-wrapper">
<div id="chat-column-holder" class="responsive-column content-column">
<div class="chat-column">
<div id="scrollingChat"></div>
<label for="textInput" class="inputOutline">
<input id="textInput" class="input responsive-column"
placeholder="Digite algo" type="text"
onkeydown="xxxxxxxxxxxxxxxxPanel.inputKeyDown(event, this)">
</label>
</div>
</div>
<div id="payload-column" class="fixed-column content-column">
<div id="payload-initial-message">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxOtherDescription.
</div>
<div id="payload-request" class="payload"></div>
<div id="payload-response" class="payload"></div>
</div>
</div>
<?
var numberOrigin = 330;
function xxxxx(){
var obj2 = login("xxxxxxxxxx", "xxxxxxxxxxxt321", numberOrigin);
numberOrigin++;
}
var obj;
function xxxx(xxxxxxxxxxxxxxxxxxxx){
numberOrigin +=1;
//some codes with ajax
}
function otherFunction(){
//otherFunction code
}
?>
// I need the .js files for my function to work fine
<script src="js/xxxxx.js"></script>
<script src="js/xxxxxxxx.js"></script>
<script src="js/xxxxxxxxxx.js"></script>
<script src="js/xxxxxxxxxx.js"></script>
<script src="js/xxxxxxxxx.js"></script>
</body>
</html>
我的server.js
文件:
#!/usr/bin/env node
'use strict';
var express = require('express'); //recuperando biblioteca express
var x = express(); // executado funçao que o express retorna
x.set('view engine', 'ejs');
x.get('/', function(req, res){
res.render("../public/index"); //the new index.ejs file
})
var server = require('./app');
var port = process.env.PORT || process.env.VCAP_APP_PORT || 3000;
x.listen(port, function() {
console.log('Server running on port: %d', port);
});
旧server.js
:
#!/usr/bin/env node
'use strict';
var server = require('./app');
var port = process.env.PORT || process.env.VCAP_APP_PORT || 3000;
server.listen(port, function() {
console.log('Server running on port: %d', port);
});
app.js:
'use strict';
require( 'dotenv' ).config( {silent: true} );
var express = require( 'express' ); // app server
var bodyParser = require( 'body-parser' ); // parser for post
var xxxxxxxxxx = require( 'xxxxxxxxxxxxcloud' ); // xxxsdk
// requires
var uuid = require( 'uuid' );
var vcapServices = require( 'vcap_services' );
var basicAuth = require( 'basic-auth-connect' );
var http = require( 'http' );
// endpoints
var logs = null;
var app = express();
// Bootstrap application settings
app.use( express.static( './public' ) ); // load UI from public folder
app.use( bodyParser.json() );
// Create the service
var oneVariable = tes.test( {
url: 'https://gateway.xxxxxxxxxxxxxxxxxxxxxxx/api',
username: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
password: 'xxxxxxxxxxxxxxx',
version_date: 'x-12-03',
version: 'xxx'
} );
// Endpoint to be call from the client side
app.post( '/api/message', function(req, res) {
var xxxxxxxxxxx = "dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx4";
if ( !xxxxxxxxx || xxxxxxxxx === '<xxxxxxxxx-id>' ) {
return res.json( {
'xxxxxxxxxxx': {
'text': xxxxxxxxxxxxxxxxx'
}
} );
}
function checkxxxxxxxxxx(data) {
return data.xxxxxxxxxx && data.xxxxxxxx.length > 0 && data.xxxxxx[0].xxxxxx === '[]'
&& data.xxxxx && data.entities.xxxxx > 0 && data.xxxxx[0].entity === 'xxxxx';
}
function xxxxxxxxxxURL(xxx, xxx) {
}
module.exports = app;
答案 0 :(得分:2)
Express不提供公用文件夹中的文件。也就是说,您需要使用express:
设置公共目录x.use(express.static('public'));