我在 SendGrid 中有一个动态模板,使用 Postman 向https://api.sendgrid.com/v3/mail/send发送 POST 请求
具有以下 json:
{
"personalizations": [{
"to": [{
"email": "dariusgoore@gmail.com",
"name": "test"
}],
"dynamic_template_data":{
"name":"John",
"text": "Someone just added a new post!",
}
}],
"from": {
"email": "team@writerboards.com",
"name": "test"
},
"reply_to": {
"email": "dariusgoore@gmail.com",
"name": "test"
},
"template_id": "d-c8f201dd360d40bc877da13a1a0b36b1"
}
Run Code Online (Sandbox Code Playgroud)
可以使用模板发送电子邮件。
但是,我似乎无法从 Express 发送类似的请求。
这是我调用 SendGrid 的路线(端点响应 cron 作业):
const express = require('express');
const User = require('../models/User');
const Act = require('../models/Act');
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
let router = express.Router();
router.get('/', async …Run Code Online (Sandbox Code Playgroud) 按照此处的 hartle 教程进行操作:https ://www.learnenough.com/action-cable-tutorial#sec-upgrading_to_action_cable
当我进行到步骤 4 时,添加 ActionCable 时聊天消息不会传输,并且出现错误:
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT ? [["LIMIT", 1]]
An unauthorized connection attempt was rejected
Run Code Online (Sandbox Code Playgroud)
这是相关文件:
room_channel.rb:
class RoomChannel < ApplicationCable::Channel
def subscribed
stream_from "room_channel"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
Run Code Online (Sandbox Code Playgroud)
消息控制器:
class MessagesController < ApplicationController
before_action :logged_in_user
before_action :get_messages
def index
end
def create
message = current_user.messages.build(message_params)
if message.save
ActionCable.server.broadcast 'room_channel',
message: render_message(message)
message.mentions.each do |mention| …Run Code Online (Sandbox Code Playgroud) 在 ExpressJS 中,我想下载之前上传到 Amazon S3 存储桶的文件。
这是我当前的路线:
const express = require('express');
const AWS = require('aws-sdk');
const mammoth = require('mammoth');
const fs = require('fs').promises
const path = require('path')
const router = express.Router();
router.put('/:id/download', async (req, res, next) => {
console.log('hitting download route')
var id = req.params.id;
let upload = await Upload.query().findById( id ).eager('user');
console.log("file to download is: ", upload.name)
AWS.config.update({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});
const s3 = new AWS.S3();
// var fileStream = fs.createWriteStream('/tmp/file.docx');
// var s3Stream = s3.getObject(params).createReadStream();
const …Run Code Online (Sandbox Code Playgroud)