我正在尝试使用bcrypt-nodejs我的sequelize模型的包,并且想要遵循一个教程将哈希合并到我的模型中,但是我收到了一个错误generateHash.我似乎无法弄清楚这个问题.有没有更好的方法来加入bcrypt?
错误:
/Users/user/Desktop/Projects/node/app/app/models/user.js:26
User.methods.generateHash = function(password) {
^
TypeError: Cannot set property 'generateHash' of undefined
at module.exports (/Users/user/Desktop/Projects/node/app/app/models/user.js:26:27)
at Sequelize.import (/Users/user/Desktop/Projects/node/app/node_modules/sequelize/lib/sequelize.js:641:30)
Run Code Online (Sandbox Code Playgroud)
模型:
var bcrypt = require("bcrypt-nodejs");
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('users', {
annotation_id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
firstName: {
type: DataTypes.DATE,
field: 'first_name'
},
lastName: {
type: DataTypes.DATE,
field: 'last_name'
},
email: DataTypes.STRING,
password: DataTypes.STRING,
}, {
freezeTableName: true
});
User.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null); …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建我的 Gatsby 站点以部署到生产环境,但我遇到了一个问题,我认为该问题与我的应用程序中的一行代码有关,我使用该代码window重定向到从发出的 GET 请求中检索的外部 URL单击按钮。我尝试阅读有关此问题的文档,并尝试使用他们的窗口检查条件,但我的重定向要么不起作用,要么收到与Can't resolve 'module'. 是否有其他方法可以替换全部的使用window或修复在构建期间运行并导致错误的原因?
错误:
failed Building static HTML for pages - 2.611s
ERROR #95312
"window" is not available during server side rendering.
Run Code Online (Sandbox Code Playgroud)
窗口代码检查错误:
WebpackError: ReferenceError: window is not defined
Run Code Online (Sandbox Code Playgroud)
代码:
authClick(e) {
e.preventDefault();
this.setState({ authorizing: true }, ()=> {
axios.get(auth_url)
.then((res) => {
this.setState({
authorizing: false
})
window.location.replace(res.data) // Window call
// Attempt to fix the issue based on documentation
// if (typeof window !== `undefined`){ …Run Code Online (Sandbox Code Playgroud) 我今天遇到了一个问题,突然间我的Elastic Beanstalk应用程序将我发送到了一个502 Bad Gateway页面.现在我遇到过这个问题,之所以发生这种情况,是因为Node命令无法启动我的服务器.我通过输入Node command: node main.js来解决这个问题,直到今天早上我都没有遇到这个问题.突然它停止工作,我在错误日志中收到此错误:
2015/03/31 13:07:17 [error] 697#0: *519 connect() failed (111: Connection refused) while connecting to upstream, client: 54.146.12.189, server: , request: "HEAD / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "54.152.12.19"
2015/03/31 13:07:17 [error] 697#0: *521 connect() failed (111: Connection refused) while connecting to upstream, client: 54.146.18.189, server: , request: "GET /clientaccesspolicy.xml HTTP/1.1", upstream: "http://127.0.0.1:8081/clientaccesspolicy.xml", host: "54.152.12.19"
2015/03/31 13:16:02 [error] 697#0: *523 connect() failed (111: Connection refused) while connecting to upstream, client: 69.204.65.1321, server: …Run Code Online (Sandbox Code Playgroud) Unhandled rejection TypeError: Cannot read property 'getTableName' of undefined当我尝试将表关联到我的查询时,我遇到了收到错误消息的问题。我在表之间有一对一的关系,但不确定这是导致错误还是在其他地方我将两个表相关联。
这是我的查询:
appRoutes.route('/settings')
.get(function(req, res, organization){
models.DiscoverySource.findAll({
where: {
organizationId: req.user.organizationId
},
include: [{
model: models.Organization, through: { attributes: ['organizationName', 'admin', 'discoverySource']}
}]
}).then(function(organization, discoverySource){
res.render('pages/app/settings.hbs',{
user: req.user,
organization: organization,
discoverySource: discoverySource
});
})
})
Run Code Online (Sandbox Code Playgroud)
这是 models.DiscoverySource 模型:
module.exports = function(sequelize, DataTypes) {
var DiscoverySource = sequelize.define('discovery_source', {
discoverySourceId: {
type: DataTypes.INTEGER,
field: 'discovery_source_id',
autoIncrement: true,
primaryKey: true
},
discoverySource: {
type: DataTypes.STRING,
field: 'discovery_source_name'
},
organizationId: {
type: DataTypes.TEXT,
field: …Run Code Online (Sandbox Code Playgroud) 我正在Amazon Elastic Beanstalk上运行Express.js应用程序并且我的环境已成功创建,但是当我通过Amazon创建的URL访问我的环境时,我收到502 Bad Gateway nginx/1.6.2错误消息.虽然我已经阅读了StackOverflow上的其他资源,建议我将主文件重命名server.js为main.js并设置port在bin/www文件夹中,但我觉得这不是我的应用程序的解决方案.我跑node server.js,这是我相信Elastic Beanstalk运行的命令,它不起作用,(错误信息):
node server.js
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [undefined:27017]
Run Code Online (Sandbox Code Playgroud)
因为我在.env文件中设置了ENV变量,所以我可以运行我的服务器的唯一方法是使用工头.这让我觉得502错误是Elastic Beanstalk无法理解变量从而导致服务器失败的结果.任何人都可以确认我是在正确的道路上或是这个问题真的是因为我的主文件被命名server.js而不是在bin/www文件夹中?
这是我server.js文件中的代码:
//Load express
var express = require('express');
var app = express();
var router = express.Router(); // get an instance of the router
var bodyParser = require('body-parser'); // configure app to use bodyParser()
var mongoose …Run Code Online (Sandbox Code Playgroud) nginx amazon-web-services node.js express amazon-elastic-beanstalk
我有一个导航视图控制器,在操作时将一个segue发送到标签栏视图控制器.由于此segue,选项卡式视图控制器继承导航栏.我正在尝试将标题应用于附加到标签栏视图控制器的我的一个视图控制器,但是通过代码设置标题对我来说不起作用.有谁知道原因可能是什么?
这是我的故事板的图片:

带有注销按钮的视图控制器是我试图在导航栏(代码)中设置标题的地方:
import UIKit
class ProfileSettingsViewController: UIViewController {
override func viewWillAppear(animated: Bool) {
self.navigationItem.title = "Profile Settings"
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.leftBarButtonItem = nil
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func logoutButton(sender: AnyObject) {
PFUser.logOut()
var currentUser = PFUser.currentUser()
self.performSegueWithIdentifier("userLoggedOut", sender: self)
self.navigationController?.setNavigationBarHidden(self.navigationController?.navigationBarHidden == false, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
嵌入导航控制器的视图控制器触发到标签栏控制器的segue:
import UIKit
class UserRegistrationViewController: UIViewController {
func displayAlert(title:String, error:String) {
var alert = UIAlertController(title: title, message: …Run Code Online (Sandbox Code Playgroud) 我正在使用该serverless框架将我的 lambda 部署到 AWS,并且已经能够通过 Postman 成功地将 POST 请求运行到与我的 lambda 函数关联的 API 网关,但是当我尝试从表单提交(AJAX 请求)运行 POST 请求时本地服务器我收到 502 错误消息,
Access to XMLHttpRequest at 'https://*id*.execute-api.us-east-1.amazonaws.com/prod/message' from origin 'http://localhost:2368' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
这是我没想到的,因为cors我的 set 中有属性serverless.ymlto true,它为 HTTP 端点设置 CORS 配置。这是函数 yaml 设置:
functions:
email:
handler: handler.sendEmail
events:
- http:
path: message
method: post
cors: true
Run Code Online (Sandbox Code Playgroud)
这是 jQuery AJAX 请求:
$.ajax({
type: 'POST',
url: 'https://*id*.execute-api.us-east-1.amazonaws.com/prod/message',
crossDomain: …Run Code Online (Sandbox Code Playgroud) 我有一个节点 NextJS 应用程序,我正在使用 Docker 对其进行容器化,然后部署到 GCP Cloud Run。虽然 Docker 在本地运行没有问题,但在部署到 Cloud Run 时会遇到错误。当我查看错误日志时,它似乎经历了各种步骤,例如安装软件包和运行迁移,没有出现问题,但随后意外失败并显示错误消息:
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
Uncaught signal: 6, pid=13, tid=13, fault_addr=0.
Uncaught signal: 6, pid=1, tid=1, fault_addr=0.
Container terminated on signal 6.
Run Code Online (Sandbox Code Playgroud)
我发现使用如此简单的应用程序遇到这种情况有点奇怪,我想知道这意味着什么以及防止这种情况发生的选项(更小的docker大小?)或解决(扩展节点内存?)
不确定需要哪些附加信息,但可能相关的是
Package.json(脚本):
"scripts": {
"dev": "nodemon server.js",
"build": "next build",
"start": "NODE_ENV=production npm run db:migrate && node server.js",
"test": "jest --watch",
"test:ci": "jest --ci",
"db:migrate": "node_modules/.bin/sequelize db:migrate",
"db:migrate:undo": "node_modules/.bin/sequelize db:migrate:undo",
"db:migrate:undo:all": "node_modules/.bin/sequelize db:migrate:undo:all",
"db:seed": "node_modules/.bin/sequelize db:seed:all", …Run Code Online (Sandbox Code Playgroud) 我有一个问题,我无法使用特定的对象值来创建记录.当它执行insert命令时,在命令开始后立即抛出错误并且永远不会创建记录.错误发生userId:user.user_id在我的路线上.
Unhandled rejection SequelizeForeignKeyConstraintError: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`test_db`.`member`, CONSTRAINT `member_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `organization` (`organization_id`) ON DELETE CASCADE ON UPDATE CASCADE)
Run Code Online (Sandbox Code Playgroud)
这是模型上的关系:
这是记录的SQL:
Executing (default): INSERT INTO `user` (`user_id`,`email`,`organization_id`,`authentication_token`,`updatedAt`,`createdAt`) VALUES (DEFAULT,'tester@vdfd.com','1','f800127f4b345d1af54d23f566eca88859898d70','2016-05-30 21:39:19','2016-05-30 21:39:19');
This user:[object SequelizeInstance:user]
41
Executing (default): INSERT INTO `member` (`member_id`,`member_email`,`organization_id`,`user_id`,`updatedAt`,`createdAt`) VALUES (DEFAULT,'tester@vdfd.com','1',41,'2016-05-30 21:39:19','2016-05-30 21:39:19');
Run Code Online (Sandbox Code Playgroud)
路线:
.post(function(req, res, user){
var token;
User.create({
email: req.body.email,
organizationId: req.body.organizationId,
authenticationToken: crypto.randomBytes(20).toString('hex')
}).then(function(user){
token = user.authenticationToken;
console.log('This user:' + …Run Code Online (Sandbox Code Playgroud) 我有一些jQuery逻辑设置,用户可以在其中提交多个字段值,这些字段值应该作为我的数据库中的单个记录创建.我以前解决这个问题的方法是将我的值映射到随后与该.bulkCreate方法一起使用的变量,但我不知道MYSQL不支持使用此方法自动递增字段.结果我决定采用我的逻辑,而是使用该.create方法创建一个for循环.不幸的是,我收到此错误消息:TypeError: this.build(...).save is not a function在行models.DiscoverySource.create(sources).为什么在我不使用构建方法时会出现此消息?
.post(function(req, res){
console.log(req.body.discoverySource);
var sources = _.map(req.body.discoverySource, function (source) {
return {
discoverySource: source,
organizationId: req.body.organizationId
};
});
console.log("These are the" + sources); //outputs "These are the [object Object],[object Object], [object Object]
console.log(sources[0].discoverySource); //outputs correctly first value
console.log(sources[0].organizationId); //outputs correctly the first value
for (i=0; i < sources.length; i++){
models.DiscoverySource.create(sources)
.then(function(){
return models.DiscoverySource.findAll();
}).then(function(discoverySource){
console.log(discoverySource);
res.redirect('/app');
}).catch(function(error){
res.send(error);
console.log('Error during Post: ' + error);
});
} …Run Code Online (Sandbox Code Playgroud) node.js ×6
sequelize.js ×4
express ×2
mysql ×2
ajax ×1
aws-lambda ×1
bcrypt ×1
docker ×1
gatsby ×1
heap-memory ×1
ios ×1
javascript ×1
nginx ×1
reactjs ×1
swift ×1
xcode ×1