aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-10-30 01:57:28 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:58 +0300
commitc8648e66150a5a7e413e4c225aa850b281dc65a2 (patch)
tree30c32ee10300994d6d55c4bacb2900ff74b1a710
parent657af5906ed50acc9bacea487ac22b6c9c961571 (diff)
express: enable body parser
-rw-r--r--vnext/package-lock.json1
-rw-r--r--vnext/package.json1
-rw-r--r--vnext/server/index.js4
-rw-r--r--vnext/server/middleware/oembed.js31
4 files changed, 8 insertions, 29 deletions
diff --git a/vnext/package-lock.json b/vnext/package-lock.json
index f5bbe545..71f29f3a 100644
--- a/vnext/package-lock.json
+++ b/vnext/package-lock.json
@@ -12,6 +12,7 @@
"@babel/register": "^7.18.9",
"axios": "^1.1.3",
"axios-cache-interceptor": "^0.10.7",
+ "body-parser": "^1.20.1",
"config": "^3.3.8",
"core-js": "^3.26.0",
"cors": "^2.8.5",
diff --git a/vnext/package.json b/vnext/package.json
index d7f9225c..2c059008 100644
--- a/vnext/package.json
+++ b/vnext/package.json
@@ -77,6 +77,7 @@
"@babel/register": "^7.18.9",
"axios": "^1.1.3",
"axios-cache-interceptor": "^0.10.7",
+ "body-parser": "^1.20.1",
"config": "^3.3.8",
"core-js": "^3.26.0",
"cors": "^2.8.5",
diff --git a/vnext/server/index.js b/vnext/server/index.js
index 729f05d6..c347739f 100644
--- a/vnext/server/index.js
+++ b/vnext/server/index.js
@@ -1,4 +1,6 @@
import express from 'express';
+import { raw } from 'body-parser';
+import cors from 'cors';
import config from 'config';
// we'll talk about this in a minute:
@@ -12,6 +14,8 @@ const path = require('path');
// initialize the application and create the routes
const app = express();
+app.use(raw());
+app.use(cors());
const router = express.Router();
router.post('/api/sender', event);
diff --git a/vnext/server/middleware/oembed.js b/vnext/server/middleware/oembed.js
index ad23d9e2..43bed194 100644
--- a/vnext/server/middleware/oembed.js
+++ b/vnext/server/middleware/oembed.js
@@ -1,39 +1,12 @@
import { embeddedTweet } from '../../src/api';
-import Cors from 'cors';
-// Initializing the cors middleware
-// You can read more about the available options here: https://github.com/expressjs/cors#configuration-options
-const cors = Cors({
- methods: ['POST', 'GET', 'HEAD'],
-});
-
-/**
- * Helper method to wait for a middleware to execute before continuing
- * And to throw an error when an error happens in a middleware
- *
- * @param {import("next").NextApiRequest} req
- * @param {import("next").NextApiResponse} res
- * @param { Function } fn
- */
-function runMiddleware(req, res, fn) {
- return new Promise((resolve, reject) => {
- fn(req, res, (result) => {
- if (result instanceof Error) {
- return reject(result);
- }
- return resolve(result);
- });
- });
-}
/**
- * Return content for embedding.
+ * Return content for embedding
*
- * @param {import("next").NextApiRequest} req
- * @param {import("next").NextApiResponse} res
+ * @type {import('express').RequestParamHandler}
*/
const oembed = async (req, res) => {
let url = (req.query.url || '').toString();
- await runMiddleware(req, res, cors);
return embeddedTweet(url).then(result => {
res.send(result);
res.end();