Chapter 4: edits
This commit is contained in:
@@ -27,6 +27,11 @@ function get(res) {
|
|||||||
res.end(form);
|
res.end(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function error(code, res) {
|
||||||
|
res.statusCode = code;
|
||||||
|
res.end(http.STATUS_CODES[code]);
|
||||||
|
}
|
||||||
|
|
||||||
function post(req, res) {
|
function post(req, res) {
|
||||||
if (!/multipart\/form-data/.test(req.headers["content-type"])) {
|
if (!/multipart\/form-data/.test(req.headers["content-type"])) {
|
||||||
error(415, res);
|
error(415, res);
|
||||||
@@ -43,16 +48,6 @@ function post(req, res) {
|
|||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
});
|
});
|
||||||
res.end(
|
res.end(JSON.stringify({fields,files,}));
|
||||||
JSON.stringify({
|
|
||||||
fields,
|
|
||||||
files,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function error(code, res) {
|
|
||||||
res.statusCode = code;
|
|
||||||
res.end(http.STATUS_CODES[code]);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
|
const http = require("http");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
|
|
||||||
// http.get('http://example.com', (res) => res.pipe(process.stdout))
|
// http.get("http://example.com", (res) => res.pipe(process.stdout));
|
||||||
|
|
||||||
const payload = `{
|
const payload = `{
|
||||||
"name": "Beth",
|
"name": "Beth",
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ http
|
|||||||
get(res);
|
get(res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.method === "POST") {
|
if (req.method === "POST") {
|
||||||
post(req, res);
|
post(req, res);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const nodemailer = require("nodemailer");
|
const nodemailer = require("nodemailer");
|
||||||
|
|
||||||
let transporter = nodemailer.createTransport({
|
const transporter = nodemailer.createTransport({
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 4321,
|
port: 4321,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user