Download app.js from kavion/quote-api: direct link, hf CLI and curl.
- Browser
- Download file 1.64 kB
-
https://huggingface.co/spaces/kavion/quote-api/resolve/main/app.js
- Command line
-
hf download hf://spaces/kavion/quote-api/app.js
-
curl -L -o app.js https://huggingface.co/spaces/kavion/quote-api/resolve/main/app.js
1.64 kB
| const logger = require('koa-logger') | |
| const responseTime = require('koa-response-time') | |
| const bodyParser = require('koa-bodyparser') | |
| const ratelimit = require('koa-ratelimit') | |
| const Router = require('koa-router') | |
| const Koa = require('koa') | |
| const { loadFonts } = require('./utils') | |
| const app = new Koa() | |
| app.use(logger()) | |
| app.use(responseTime()) | |
| app.use(bodyParser()) | |
| const ratelimitDb = new Map() | |
| app.use(ratelimit({ | |
| driver: 'memory', | |
| db: ratelimitDb, | |
| duration: 1000 * 55, | |
| errorMessage: { | |
| ok: false, | |
| error: { | |
| code: 429, | |
| message: 'Rate limit exceeded. See "Retry-After"' | |
| } | |
| }, | |
| id: (ctx) => ctx.ip, | |
| headers: { | |
| remaining: 'Rate-Limit-Remaining', | |
| reset: 'Rate-Limit-Reset', | |
| total: 'Rate-Limit-Total' | |
| }, | |
| max: 20, | |
| disableHeader: false, | |
| whitelist: (ctx) => { | |
| // The bot sends its token in the request body (kept out of the URL/access | |
| // logs); accept either location so its own requests stay un-throttled. | |
| const token = ctx.query.botToken || (ctx.request.body && ctx.request.body.botToken) | |
| return token === process.env.BOT_TOKEN | |
| }, | |
| blacklist: (ctx) => { | |
| } | |
| })) | |
| app.use(require('./helpers').helpersApi) | |
| const route = new Router() | |
| const routes = require('./routes') | |
| // Health check endpoint for Docker/Coolify | |
| route.get('/health', (ctx) => { | |
| ctx.status = 200 | |
| ctx.body = { status: 'ok', timestamp: Date.now() } | |
| }) | |
| route.use('/*', routes.routeApi.routes()) | |
| app.use(route.routes()) | |
| const port = process.env.PORT || 3000 | |
| async function start () { | |
| await loadFonts() | |
| app.listen(port, () => { | |
| console.log('Listening on localhost, port', port) | |
| }) | |
| } | |
| start() | |