使用Express进行Vue.js路由

我在这里创build了一个组合https://temp-portfolio.herokuapp.com 。 我的问题是,当用户刷新除index.html以外的页面或直接到另一个链接,如https://temp-portfolio.herokuapp.com/projects路由不呈现。 我已经使用Node.js和Express在Heroku按照本指南设置了一切https://medium.com/@sagarjauhari/quick-n-clean-way-to-deploy-vue-webpack-apps-on-heroku- b522d3904bc8 。 我试图重写服务器到这个https://stackoverflow.com/a/44226999/4178637,但应用程序崩溃。 server.js var express = require('express'); var path = require('path'); var serveStatic = require('serve-static'); app = express(); app.use(serveStatic(__dirname)); var port = process.env.PORT || 5000; app.listen(port); console.log('server started '+ port); index.js import Vue from 'vue' import Router from 'vue-router' import Nav from '@/components/Nav' import Home from '@/components/Home' import Projects from […]

在中间件中发出一个Post请求

我是Express JS和Node JS的新手。 我打算在Express Middleware中手动实现Auth-Server,我使用https://github.com/ranm8/requestify发出请求 const requestify = require('requestify'); app.use(function (req, res, next) { var config = require('./config-' + process.env.REACT_APP_ENV) var redirect = config.ADMIN_UI_URL // Perform login to Auth-Server if (req.originalUrl.startsWith('/?code')) { let auth_code = req.query.code let params = { 'grant_type': 'authorization_code', 'code': auth_code, 'client_id': config.OAUTH_CLIENT_ID, 'redirect_uri': redirect } requestify.post(config.OAUTH_ID_URL+'/oauth2/token', params).then(function(response) { console.log(response.getBody()); // There […]

如何find哪些promise在nodejs中未处理UnhandledPromiseRejectionWarning?

从版本7的nodejs有asynchronous等待处理承诺的sintactic糖,在我的apis下面的警告经常出现: (node:11057) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: Error: Can't set headers after they are sent. (node:11057) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 不幸的是,没有提到渔获缺失的地方。 有没有办法find它没有检查每个try catch块?

login使用Twitter

我试图在我的node.js app 使用Twitter实现SingIn 。 首先,我打电话给https://api.twitter.com/oauth/request_token给我oauth_token ,然后打电话给https://api.twitter.com/oauth/authenticate?oauth_token=TWITTER_OAUTH_TOKEN打开一个新窗口这表明用户可以接受这个应用程序signIn。 用户接受后,twitter用oauth_token和oauth_verifier调用一个callback url 。 现在我打电话https://api.twitter.com/oauth/access_token获取access_token 。 我得到access_token就像给定的格式 { oauth_token: 'NEW_TWITTER_OAUTH_TOKEN', oauth_token_secret: 'NEW_TWITTER_OAUTH_TOKEN_SECRET', user_id: 'TWITTER_USER_ID', screen_name: 'TWITTER_SCREEN_NAME', x_auth_expires: '0' } 现在我试图获得更多的用户信息,如user_email, user_pic etc 。 我使用以下参数调用以下API https://api.twitter.com/1.1/account/verify_credentials.json : let hmac = crypto.createHmac('sha1', 'thisIsTest'); hmac.update(uuid.v4()); let hash = hmac.digest('hex'); var profileOauth = { oauth_consumer_key: 'twitter_consumer_key', oauth_nonce: uuid.v4(), oauth_signature_method:'HMAC-SHA1', oauth_signature: hash, oauth_timestamp: Date.parse(new Date()), […]

如何使用ejs获取节点js中checkbox的值?

我的代码: Html档案: <form action="/form" method="post" enctype="multipart/form-data"> Name: <input type="text" name="name" /><br> Email: <input type="email" name="email" /> <br> Age: <input type="number" name="age" /> <br> Address: <textarea name="address" rows="10" cols="15"> </textarea><br> Category: <select name="cat"> <option value="1">Php</option> <option value="2">NodeJs</option> <option value="3">jQuery</option> </select><br> Gender: <input type="radio" name="gen" value="m"/> Male <input type="radio" name="gen" value="f"/> Female Hobby: <input type="checkbox" name="hob[]" value="cri"/> […]

Laravel-mix – BrowserSync在event.js上抛出错误:160

不知道这个问题是否与laravel-mix相关,但是我对Browsersync软件包有问题。 这是我的mix.js: mix.js('resources/assets/js/app.js', 'public/js') .browserSync({proxy: 'localhost:8000'}) .sass('resources/assets/sass/app.scss', 'public/css'); 当我运行npm run watch-poll ( watch不接受更改,因此watch-poll 在这里看到 )我在控制台上得到以下错误: [Browsersync] Watching files… events.js:160 throw er; // Unhandled 'error' event ^ Error: watch resources/views/auth/passwords ENOSPC at exports._errnoException (util.js:1020:11) at FSWatcher.start (fs.js:1443:19) at Object.fs.watch (fs.js:1470:11) at createFsWatchInstance (/home/tanmay/LVProjects/learningdemo/node_modules/chokidar/lib/nodefs-handler.js:37:15) at setFsWatchListener (/home/tanmay/LVProjects/learningdemo/node_modules/chokidar/lib/nodefs-handler.js:80:15) at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/tanmay/LVProjects/learningdemo/node_modules/chokidar/lib/nodefs-handler.js:228:14) at FSWatcher.NodeFsHandler._handleDir (/home/tanmay/LVProjects/learningdemo/node_modules/chokidar/lib/nodefs-handler.js:407:19) at FSWatcher.<anonymous> (/home/tanmay/LVProjects/learningdemo/node_modules/chokidar/lib/nodefs-handler.js:455:19) at […]

node.js mongoose chai-http RESTful APItesting(唯一字段)的行为与手动ARC APItesting不同

各位开发者, 我编写了一个基于node.js和mongoose的RESTful API服务器。 在编写相应的testing时,我对使用chai-http进行自动化testing和使用ARC(高级REST客户端,chrome插件)的手动APItesting之间的明显不同之处有着奇怪的体验。 我的用户模型(见下面的定义)有一个唯一的“用户名”字段。 当我使用ARC使用现有的用户名login新用户时,我按照预期从mongodb驱动程序中获取E11000。 当我这样做(至less我这样认为)使用chai-http.request.post,我得到一个statuscode 200,一个SUCCESS结果,我有两个用户在我的testing数据库集合中具有相同的用户名! 用户模式模式,包括/挂钩/导出等。ommited: const userSchema = new Schema({ admin_info: AdminInfo, role: { type: String, required: true}, username: { type: String, required: true, unique: true, index: { unique: true } }, password: { type: String, required: true }, firstname: String, lastname: String, mail: String, }); 用于POST /用户的通用路由处理函数,其中“model”是上述用户模式的一个实例: function addEntry(req, res, […]

如何阅读node.js中的多部分表单

我有一个node.js应用程序,目前只支持x-www-form-urlencoded请求。 如果有人需要发送一个文件作为附件,我必须扩大对表单数据的支持。 从请求读取数据目前使用DecodeURIComponent完成,看起来类似于以下。 是否有可能适应这个阅读表单数据? exports.parseUrlEncodedBody = function(event) { //This is to extract url encoded data var temp = {}; if (event.body) { // retrieve keys & values var pm = event.body.split("&"); // store keys and values in temp object params.forEach(function (item, index, array) { var keyValue = item.split("="); var key, value; if (keyValue.length >= 1) […]

如何使用node4iler包使用Angular 4和Node Js发送电子邮件

<!– Server.js file of Node JS–> var http = require('http'); var nodemailer = require('nodemailer'); var bodyParser = require('body-parser'); var connect = require('connect'); var app = connect(); app.use( bodyParser.json() ); // to support JSON-encoded bodies app.use(bodyParser.urlencoded({ // to support URL-encoded bodies extended: true })); sendemail = function(request, response, next){ var transporter = nodemailer.createTransport({ service: 'gmail', auth: […]

JavaScript(节点js)在读取Excel文件时跳过空单元格

我正在做一个小的任务来读取Excel工作表并保存为json格式。 我使用的代码在所有单元格值存在的情况下运行良好,如果有空单元格跳过该单元格。 如果没有提供任何值(在我的情况下,我错过了cust2电话号码),我想要的输出如下。 [ { cust_name: 'Ben', cust_city: 'Street1', cust_country: 'country1', phno: 1 }, { cust_name: 'Ken', cust_city: 'street2', cust_country: 'country2' phno:}, { cust_name: 'Ron', cust_city: 'street3', cust_country: 'country3', phno: 3 } ] 但是我得到的输出是 [ { cust_name: 'Ben', cust_city: 'Street1', cust_country: 'country1', phno: 1 }, { cust_name: 'Ken', cust_city: 'street2', cust_country: 'country2' }, { cust_name: […]