Compare commits
No commits in common. 'main' and 'develop' have entirely different histories.
File diff suppressed because it is too large
Load Diff
@ -1,88 +0,0 @@
|
||||
import fastify from 'fastify'
|
||||
import dotenv from 'dotenv'
|
||||
import path from 'path'
|
||||
import { EventEmitter } from 'events'
|
||||
import formBody from '@fastify/formbody'
|
||||
|
||||
// getting .env
|
||||
dotenv.config({ path: path.join(path.resolve(), '/../../.env') })
|
||||
|
||||
// create server
|
||||
const server = fastify()
|
||||
|
||||
// adding eventEmitter
|
||||
server.decorate('eventEmitter', new EventEmitter())
|
||||
|
||||
// adding formBody
|
||||
server.register(formBody)
|
||||
|
||||
/**
|
||||
* add xmpp
|
||||
*
|
||||
*/
|
||||
|
||||
import xmpp from './plugins/xmpp.js'
|
||||
|
||||
server.register(xmpp, {
|
||||
service: process.env.XMPP_SERVICE,
|
||||
domain: process.env.XMPP_DOMAIN,
|
||||
username: process.env.XMPP_USERNAME,
|
||||
password: process.env.XMPP_PASSWORD,
|
||||
to: process.env.XMPP_TO
|
||||
})
|
||||
|
||||
/**
|
||||
* add helmet
|
||||
*
|
||||
*/
|
||||
|
||||
import helmet from '@fastify/helmet'
|
||||
|
||||
/***
|
||||
server.register(
|
||||
helmet, {
|
||||
referrerPolicy: {
|
||||
policy: ['origin']
|
||||
}
|
||||
}
|
||||
)*/
|
||||
|
||||
/**
|
||||
* add rateLimit
|
||||
*
|
||||
*/
|
||||
|
||||
import rateLimit from '@fastify/rate-limit'
|
||||
|
||||
const rateLimitSettings = {
|
||||
max: 100,
|
||||
timeWindow: 60000
|
||||
}
|
||||
|
||||
if (process.env.APP_RATE_LIMIT_MAX) {
|
||||
rateLimitSettings.max = process.env.APP_RATE_LIMIT_MAX
|
||||
}
|
||||
|
||||
if (process.env.APP_RATE_LIMIT_TIMEWINDOW) {
|
||||
rateLimitSettings.timeWindow = process.env.APP_RATE_LIMIT_TIMEWINDOW
|
||||
}
|
||||
|
||||
server.register(rateLimit, rateLimitSettings)
|
||||
|
||||
/**
|
||||
* add routes
|
||||
*
|
||||
*
|
||||
*/
|
||||
import webhookHttp from './http/api/webhook.js'
|
||||
import healthHttp from './http/api/health.js'
|
||||
|
||||
server
|
||||
.register(webhookHttp, {
|
||||
'prefix': '/api/webhook'
|
||||
})
|
||||
.register(healthHttp, {
|
||||
'prefix': '/api/health'
|
||||
})
|
||||
|
||||
export default server
|
@ -0,0 +1,41 @@
|
||||
import fastify from 'fastify'
|
||||
import dotenv from 'dotenv'
|
||||
import path from 'path'
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
// getting .env
|
||||
dotenv.config({ path: path.join(path.resolve(), '/../../.env') })
|
||||
|
||||
// create server
|
||||
const server = fastify()
|
||||
|
||||
// adding eventEmitter
|
||||
server.decorate('eventEmitter', new EventEmitter())
|
||||
|
||||
// adding xmpp
|
||||
import xmpp from './plugins/xmpp.js'
|
||||
|
||||
server.register(xmpp, {
|
||||
service: process.env.XMPP_SERVICE,
|
||||
domain: process.env.XMPP_DOMAIN,
|
||||
username: process.env.XMPP_USERNAME,
|
||||
password: process.env.XMPP_PASSWORD
|
||||
})
|
||||
|
||||
/**
|
||||
* add routes
|
||||
*
|
||||
*
|
||||
*/
|
||||
import webhookHttp from './http/api/webhook.js'
|
||||
import healthHttp from './http/api/health.js'
|
||||
|
||||
server
|
||||
.register(webhookHttp, {
|
||||
'prefix': '/api/webhook'
|
||||
})
|
||||
.register(healthHttp, {
|
||||
'prefix': '/api/health'
|
||||
})
|
||||
|
||||
export default server
|
@ -1,40 +0,0 @@
|
||||
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
|
@ -1,23 +0,0 @@
|
||||
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
|
@ -1,18 +1,14 @@
|
||||
import server from './_bootstrap.js'
|
||||
import server from './bootstrap.js'
|
||||
|
||||
// let it rain
|
||||
const start = async () => {
|
||||
try {
|
||||
await server.listen({
|
||||
port: process.env.APP_PORT
|
||||
})
|
||||
|
||||
console.log('Server: start')
|
||||
console.log('Server: running on port ' + process.env.APP_PORT)
|
||||
await server.listen(process.env.APP_PORT)
|
||||
console.log('Server is running on port ' + process.env.APP_PORT)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
start()
|
||||
start()
|
File diff suppressed because it is too large
Load Diff
@ -1,19 +1,16 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "server",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@fastify/formbody": "^7.4.0",
|
||||
"@fastify/helmet": "^11.0.0",
|
||||
"@fastify/rate-limit": "^8.0.1",
|
||||
"@xmpp/client": "^0.13.1",
|
||||
"@xmpp/client": "^0.13.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"fastify": "^4.19.2",
|
||||
"fastify-plugin": "^4.5.0",
|
||||
"isomorphic-dompurify": "^1.7.0"
|
||||
"fastify": "^3.24.0",
|
||||
"fastify-formbody": "^5.2.0",
|
||||
"isomorphic-dompurify": "^0.16.0"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue