generated from CodeChefVIT/hacktoberfest-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from RajatSablok/main
Added Node app to summarize TOS
- Loading branch information
Showing
6 changed files
with
1,933 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const express = require("express"); | ||
const request = require("request"); | ||
|
||
require("dotenv").config(); | ||
|
||
const router = express.Router(); | ||
|
||
//Get summary of terms of service or privacy policy from a URL | ||
router.post("/", async (req, res) => { | ||
const { url, sentences } = req.body; | ||
|
||
const options = { | ||
method: "GET", | ||
url: | ||
"https://meaningcloud-summarization-v1.p.rapidapi.com/summarization-1.0", | ||
qs: { | ||
url, | ||
sentences, | ||
}, | ||
headers: { | ||
"x-rapidapi-host": "meaningcloud-summarization-v1.p.rapidapi.com", | ||
"x-rapidapi-key": process.env.APIKEY, | ||
accept: "application/json", | ||
useQueryString: true, | ||
}, | ||
}; | ||
|
||
request(options, function (error, response, body) { | ||
if (error) { | ||
return res.status(500).json({ | ||
message: "Something went wrong", | ||
error: error.toString(), | ||
}); | ||
} | ||
|
||
let summary = JSON.parse(body); | ||
res.status(200).json({ summary: summary.summary }); | ||
}); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const express = require("express"); | ||
const bodyParser = require("body-parser"); | ||
const helmet = require("helmet"); | ||
const cors = require("cors"); | ||
|
||
require("dotenv").config(); | ||
|
||
const app = express(); | ||
|
||
//Use helmet to prevent common security vulnerabilities | ||
app.use(helmet()); | ||
|
||
//Use body-parser to parse json body | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
|
||
// Allow CORS | ||
app.use((req, res, next) => { | ||
res.header("Access-Control-Allow-Origin", "*"); | ||
res.header( | ||
"Access-Control-Allow-Headers", | ||
"Origin, X-Requested-With, Content-Type, Accept, Authorization, auth-token" | ||
); | ||
if (req.method === "OPTIONS") { | ||
res.header("Access-Control-Allow-Methods", "PUT, POST, PATCH, DELETE, GET"); | ||
return res.status(200).json({}); | ||
} | ||
next(); | ||
}); | ||
|
||
app.use(cors()); | ||
|
||
app.use("/api/v1/summarize", require("./api/routes/summarize")); | ||
|
||
//This function will give a 404 response if an undefined API endpoint is fired | ||
app.use((req, res, next) => { | ||
const error = new Error("Route not found"); | ||
error.status = 404; | ||
next(error); | ||
}); | ||
|
||
app.use((error, req, res, next) => { | ||
res.status(error.status || 500); | ||
res.json({ | ||
error: { | ||
message: error.message, | ||
}, | ||
}); | ||
}); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
|
||
//Start the server | ||
app.listen(PORT, () => { | ||
console.log(`Listening on port ${PORT}`); | ||
}); |
Oops, something went wrong.