Tag: javascript

Graphql:必须提供查询string

我有一个简单的快递graphql服务器: const schema = require('./schema'); const express = require('express'); const graphqlHTTP = require('express-graphql'); const cors = require('cors') const bodyParser = require('body-parser'); const app = express(); app.use(cors()); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.use('/graphql', graphqlHTTP(req => { return ({ schema, pretty: true, }) })); const server = app.listen(9000, err => { if (err) { return err; } […]

为什么使用“”快速附加对象数组名称

我正在使用Node.js / Express.js后端。 在前端,我以这种方式将一个对象传递给我的后端API。 var accountData = {"my_tags" : ["tag1", "tag2", "tag3"]} $.post("/api/submission/1", accountData, function(sucess){ console.log("success"); }); 在后端app.js是这样设置的 var app = express(); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', index); app.use('/api', api); 然后在我的api router.post("/api/submission/:pageNumber", function (req, res) { console.log(JSON.stringify(req.body)); 打印{“my_tags []”:[“tag1”,“tag2”,“tag3”]} 为什么Node或Express将“[]”附加到“my_tags”对象数组的名称上?

来自React的快速POST请求返回空主体

你好,我正在做一个反应/expression应用程序。 我已经能够从我的服务器发出GET请求,但是,我无法发出POST请求。 当我这样做,我的服务器正在返回一个空的身体。 我有身体分析器作为依赖,接受JSON作为内容,但仍然没有运气与空的身体。 我的代码和服务器/客户端的依赖关系如下。 请让我知道,如果你们看到我不。 Index.js const express = require('express'); const path = require('path'); const app = express(); const bodyParser = require('body-parser'); //routes require('./routes/sendMessageToEmail')(app); require('./routes/helloWorld')(app); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(express.static(path.join(__dirname, 'client/build'))); app.get('*', (req, res) => { res.sendFile(path.join(__dirname+'/client/build/index.html')); }); const port = process.env.PORT || 1111; app.listen(port); 例如,当我在我的index.js文件中声明路由的地方切换命令时,在之后声明路由行 app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); 行,我得到一个不确定的反对一个空的身体。 邮政路线 […]

在手柄栏中的样式

我是新来的烬,可以使用一些帮助,试图风格我创build的进度栏。 这就是创build进度条的过程: {{ember-progress-bar style=myStyle shape="Circle" useDefaultStep=false progress=model.points options=(hash strokeWidth=5 duration=600)}} 我想在控制器中使用这个代码来devise它的样式: export default Ember.Controller.extend({ myStyle: "color: #3a3a3a" }); 但是这不起作用。 任何build议,我需要做什么不同?

在中间件中发出一个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 […]

如何使用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"/> […]

如何阅读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) […]

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: […]

使用grunt压缩图像

我安装了node,npm,然后grunt。然后,我尝试在Gruntfile.Js中压缩写下面的代码的图片: grunt.initConfig({ responsive_images: { dev: { options: { engine: 'im', sizes: [{ width:800 , suffix:'_large_1x' , quality: 30 }] }, 和我的HTML文件中的img如下所示: <img src="images_src/still_life-800_large_1x.jpg"> 然而,当我刷新网页时,我检查了开发人员工具中的“networking”,图片“无法响应数据”!

WebPush UnauthorizedRegistration 400尝试从节点Js发送推送通知时出错

我正尝试使用来自NodeJS的Web Push发送推送通知。 以下是我在前端获取订阅的方式: swRegistration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: "SOME_APPLICATION_PUBLIC_KEY" })….. 这里是我用来发送推送通知的NodeJS: const webpush = require('web-push'); const options = { vapidDetails: { subject: 'mailto:SOME_MAIL_ID', publicKey: 'SOME_PUBLIC_KEY', privateKey: 'SOME_PRIVATE_KEY' } }; const pushSubscription = {"endpoint":"https://fcm.googleapis.com/fcm/send/SOME_END_POINT","keys{"p256dh":"SOME VALUE","auth":"SOME_VALUE"}}; webpush.sendNotification(pushSubscription, "Test Notification", options) .then(function(response) { console.log(response) }) .catch(function(error) {console.log(error)}); 然后我得到一个400错误。 我已经交叉validation了我的gcm_sender_id和我的服务器密钥。 一切看起来不错,通知在Firefox中testing正常工作,并在Chrome中失败。 这是我得到的错误: name: 'WebPushError', message: 'Received unexpected response code', statusCode: […]