Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
HerrHase | aa1a6c7f99 | 2 years ago |
HerrHase | 25faa9f629 | 2 years ago |
HerrHase | 5c0e64d71c | 2 years ago |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@
|
||||
import DOMPurify from 'isomorphic-dompurify'
|
||||
|
||||
/**
|
||||
*
|
||||
* handle parser
|
||||
*
|
||||
*
|
||||
* @author Björn Hase <me@herr-hase.wtf>
|
||||
* @license http://opensource.org/licenses/MIT The MIT License
|
||||
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
|
||||
*
|
||||
*/
|
||||
|
||||
async function parserHandler(request, response) {
|
||||
|
||||
// getting allowed parsers from .env as array
|
||||
const allowedParsers = process.env.APP_API_ALLOWED_PARSERS.split(',')
|
||||
|
||||
// getting name from request
|
||||
const parserName = DOMPurify.sanitize(request.params.parser)
|
||||
|
||||
// if parser not found send 404
|
||||
if (allowedParsers.indexOf(parserName) === -1) {
|
||||
|
||||
console.log('Parsers: "' + parserName + '" not found!')
|
||||
|
||||
return response
|
||||
.code(404)
|
||||
.send()
|
||||
}
|
||||
|
||||
// getting parser and set body to parser
|
||||
const Parser = await import('./../parsers/' + parserName + '.js')
|
||||
|
||||
response.locals = {
|
||||
parser: new Parser.default(request.body)
|
||||
}
|
||||
}
|
||||
|
||||
export default parserHandler
|
@ -0,0 +1,23 @@
|
||||
import DOMPurify from 'isomorphic-dompurify'
|
||||
|
||||
/**
|
||||
* handle token
|
||||
*
|
||||
* @author Björn Hase <me@herr-hase.wtf>
|
||||
* @license http://opensource.org/licenses/MIT The MIT License
|
||||
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
|
||||
*
|
||||
*/
|
||||
|
||||
async function tokenHandler(request, response) {
|
||||
|
||||
const token = DOMPurify.sanitize(request.params.token)
|
||||
|
||||
if (token !== process.env.APP_API_TOKEN) {
|
||||
return response
|
||||
.code(401)
|
||||
.send()
|
||||
}
|
||||
}
|
||||
|
||||
export default tokenHandler
|
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,19 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "server",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@xmpp/client": "^0.13.0",
|
||||
"@fastify/formbody": "^7.4.0",
|
||||
"@fastify/helmet": "^11.0.0",
|
||||
"@fastify/rate-limit": "^8.0.1",
|
||||
"@xmpp/client": "^0.13.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"fastify": "^3.24.0",
|
||||
"fastify-formbody": "^5.2.0",
|
||||
"isomorphic-dompurify": "^0.16.0"
|
||||
"fastify": "^4.19.2",
|
||||
"fastify-plugin": "^4.5.0",
|
||||
"isomorphic-dompurify": "^1.7.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue