parent
a55ba97b57
commit
c4792ca3fc
@ -0,0 +1,126 @@
|
||||
# ---> Node
|
||||
# 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/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# 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
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# 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
|
||||
public/css/*
|
||||
public/js/*
|
||||
!public/css/.gitkeep
|
||||
!public/js/.gitkeep
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# Static
|
||||
/static
|
||||
!/static/.gitkeep
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,10 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "siteomat-api",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
"start": "yarn workspace server run start"
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
import fastify from 'fastify'
|
||||
import dotenv from 'dotenv'
|
||||
import path from 'path'
|
||||
|
||||
// getting .env
|
||||
dotenv.config({ path: path.join(path.resolve(), '/../../.env') })
|
||||
|
||||
// create server
|
||||
const server = fastify()
|
||||
|
||||
// add rate limit
|
||||
import rateLimit from '@fastify/rate-limit'
|
||||
|
||||
server.register(rateLimit, {
|
||||
max: !process.env.APP_RATE_LIMIT_MAX ? 100 : process.env.APP_RATE_LIMIT_MAX,
|
||||
timeWindow: !process.env.APP_RATE_LIMIT_TIMEWINDOW ? 60000 : process.env.APP_RATE_LIMIT_TIMEWINDOW
|
||||
})
|
||||
|
||||
/**
|
||||
* add routes
|
||||
*
|
||||
*
|
||||
*/
|
||||
import jsonHttp from './http/api/json.js'
|
||||
|
||||
server
|
||||
.register(jsonHttp, {
|
||||
'prefix': '/api'
|
||||
})
|
||||
|
||||
export default server
|
@ -0,0 +1,63 @@
|
||||
import fs from 'fs'
|
||||
|
||||
/**
|
||||
* handle pages
|
||||
*
|
||||
* @author Björn Hase
|
||||
* @license hhttps://www.gnu.org/licenses/gpl-3.0.en.html GPL-3
|
||||
* @link https://gitea.node001.net/HerrHase/tellme-bot.git
|
||||
*
|
||||
*/
|
||||
|
||||
export default async function(fastify, opts)
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {object} request
|
||||
* @param {object} response
|
||||
*
|
||||
*/
|
||||
fastify.get('/v1/:name', async function (request, response) {
|
||||
|
||||
// create file path
|
||||
const filePath = process.env.APP_PUBLIC_PATH + '/' + request.params.name + '.json'
|
||||
|
||||
// if file not exists
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return response
|
||||
.code(404)
|
||||
.send()
|
||||
}
|
||||
|
||||
// loading data
|
||||
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
||||
|
||||
// results
|
||||
let results = []
|
||||
|
||||
// filter
|
||||
if (request.query.filter) {
|
||||
data.forEach((single) => {
|
||||
|
||||
})
|
||||
} else {
|
||||
results = data
|
||||
}
|
||||
|
||||
// getting offset
|
||||
let offset = !request.query.offset ? 0 : request.query.offset
|
||||
|
||||
// getting limit
|
||||
let limit = !request.query.limit ? results.length : request.query.limit
|
||||
|
||||
// offset and limit
|
||||
results = results.slice(offset, limit)
|
||||
|
||||
response
|
||||
.header('Content-Type', 'application/json; charset=utf-8')
|
||||
.code(200)
|
||||
.send(results)
|
||||
})
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
import server from './bootstrap.js'
|
||||
|
||||
// let it rain
|
||||
const start = async () => {
|
||||
|
||||
const port = !process.env.APP_PORT ? 3000 : process.env.APP_PORT
|
||||
|
||||
try {
|
||||
|
||||
await server.listen({
|
||||
port: port
|
||||
})
|
||||
|
||||
console.log('Server started! Run on Port ' + port)
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
start()
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "server",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@fastify/rate-limit": "^7.6.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"fastify": "^4.11.0",
|
||||
"fastify-formbody": "^5.3.0",
|
||||
"isomorphic-dompurify": "^0.26.0"
|
||||
}
|
||||
}
|
Loading…
Reference in new issue