我的代码表现得非常奇怪,首先,我无法让CSS工作。 在我的代码中,随机有几行变成灰色,就像是注释,但没有注释,我在每一行的末尾都按了空格键,然后恢复正常,这很奇怪。 那么每当我尝试给css属性和类时,它都不会给它们。我刚刚重新打开计算机,最后一次运行良好。 我在html中给出了指向CSS样式表的正确链接,已通过ive检查。
这只是一个例子:
home.php
var express = require('express');
var bodyParser = require('body-parser');
var request = require('request-promise');
var session = require('express-session');
const cookieParser = require('cookie-parser');
var app = express();
const rocketChatServer = '*redacted*';
const rocketChatAdminUserId = '*redacted*';
const rocketChatAdminAuthToken = '*redacted*';
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//CORS in case you need
app.use((req, res, next) => {
res.set('Access-Control-Allow-Origin', '*redacted*');
res.set('Access-Control-Allow-Credentials', 'true');
next();
});
// define middleware
const middleware = [
cookieParser(),
session({
secret: 'super-secret-key',
key: 'super-secret-cookie',
resave: true,
saveUninitialized: true,
cookie: { maxAge: 1209600000 } // two weeks in miliseconds
})
]
app.use(middleware);
//var createOrLoginUser = require('./rocketchat');
app.get('/', (req, res) => {
if(req.session.rocketchatAuthToken){
res.send(`
<html>
<body>
<iframe width='100%;' height='100%' src="*redacted*"
frameborder="0"></iframe>
</body>
</html>`);
}else{
res.send(`
<form method="post" action="/login">
<input type="text" placeholder="username" name="username">
<input type="text" placeholder="firstName"
name="firstname">
<input type="text" placeholder="Email" name="email">
<input type="text" placeholder="Pass" name="password">
<input type="submit" value="Submit">
</form>
`);
}
})
app.post('/login', async (req, res) => {
// ....CODE TO LOGIN USER
var username = req.body.username;
var pass = req.body.password;
var email = req.body.email;
var name = req.body.firstname;
// Creating or login user into Rocket chat
try {
// Request of login for 3rd party API
var options = { method: 'GET',
url: '*redacted*',
qs:
{ hashKey: '*redacted*',
sitename: username,
password: pass },
headers:
{ 'Postman-Token': '*redacted*',
'Cache-Control': 'no-cache' } };
const third_party_response = await request(options);
var result_third_party = JSON.parse(third_party_response);
console.log(result_third_party);
console.log(result_third_party.email);
if(result_third_party.email != ''){
// Request of login for Rocket Chat
var options = { method: 'POST',
url: `${rocketChatServer}/api/v1/login`,
headers:
{ 'Postman-Token': '*redacted*',
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded' },
form: { username: username, password: pass } };
const response = await request(options);
var result = JSON.parse(response);
req.session.rocketchatAuthToken = result.data.authToken;
res.redirect('/');
}else{
res.send('You are not registered with 3rd party API!');
}
} catch (ex) { console.log('CATHCh');
if (ex.statusCode === 401) {
// User does not exist, creating user
var options = { method: 'POST',
url: '*redacted*',
headers:
{ 'Postman-Token': '*redacted*',
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded',
'X-User-Id': rocketChatAdminUserId,
'X-Auth-Token': rocketChatAdminAuthToken },
form:
{ name: name ,
email: email,
password: pass,
username: username } };
const response_register = await request(options);
var result_register = JSON.parse(response_register);
if(result_register.success){
// on success login users
var options = { method: 'POST',
url: `${rocketChatServer}/api/v1/login`,
headers:
{ 'Postman-Token': '*redacted*',
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded' },
form: { username: username, password: pass } };
const response = await request(options);
var result = JSON.parse(response);
req.session.rocketchatAuthToken = result.data.authToken;
res.redirect('/');
}else{
console.log('Failed to create account');
}
// Perfom login
//return await loginUser(email, password);
} else {
throw ex;
}
}
})
// This method will be called by Rocket.chat to fetch the login token
app.get('/api/v1/rocket_chat_auth_get', (req, res) => {
if (req.session.rocketchatAuthToken) {
res.send({ loginToken: req.session.rocketchatAuthToken })
return;
} else {
res.status(401).json({ message: 'User not logged in'});
return;
}
})
// This method will be called by Rocket.chat to fetch the login token
// and is used as a fallback
app.get('/api/v1/rocket_chat_iframe', (req, res) => {
const rocketChatServer = '*redacted*';
if (req.session.rocketchatAuthToken) {
return res.send(`<script>
window.parent.postMessage({
event: 'login-with-token',
loginToken: '${ req.session.rocketchatAuthToken }'
}, '${ rocketChatServer }');
</script>
`)
return;
} else {
return res.redirect('/login');
}
})
app.listen(3030, function () {
console.log('Example app listening on port 3030!');
});
stylesheet.css
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="homestyle.css"
media="screen" />
</head>
(... more code)
<h1 class="lorem">hello</h1>
答案 0 :(得分:0)
更改
<link rel="stylesheet" type="text/css" href="homestyle.css"
media="screen" />
通过
<link rel="stylesheet" type="text/css" href="stylesheet.css" media="screen">
因为文件名为stylesheet.css
,而您调用了homestyle.css
,或者只是将CSS文件重命名为homestyle.css
。