Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance #69

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
NODE_ENV=development
APP_PORT=3000
DB_CLIENT=sqlite3
DB_DATABASE=axeapi
DB_DATABASE=axeapi
LOG_LEVEL=debug
LOG_TRANSPORT=pino-pretty
DOCS=true
209 changes: 206 additions & 3 deletions app/config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,79 @@
import { IApplicationConfig } from "axe-api";
import { CacheStrategies, IApplicationConfig } from "axe-api";
import path from "path";
import errorHandler from "./v1/Handlers/ErrorHandler";

const config: IApplicationConfig = {
/**
* This is the default API prefix that will be used in all routes.
*
* @example GET /api/v1/users
* @link https://axe-api.com/reference/api-configs.html#prefix
*/
prefix: "api",

/**
* Enable or disable auto-created API documentation.
*
*
* @link https://axe-api.com/learn/documentation.html#auto-created-api-docs
*/
docs: process.env.DOCS === "true" || true,

/**
* It means which environment your API will work. Some examples; are
* development, testing, staging, and production.
*
* You SHOULD use production for the production environment to protect
* sensitive data.
*
* @link https://axe-api.com/reference/api-configs.html#env
*/
env: process.env.NODE_ENV || "production",

/**
* It means in which port the application will run. You can select any port
* that is available for your setup.
*
* @example 3000
* @link https://axe-api.com/reference/api-configs.html#port
*/
port: process.env.APP_PORT ? parseInt(process.env.APP_PORT) : 3000,

/**
* Error handler is a routine or mechanism in software that manages and
* responds to errors or exceptions during program execution, ensuring
* graceful handling and potentially preventing program termination.
*
* You can set a global error handler in here.
*
* @link https://axe-api.com/learn/error-handling.html#error-handler
*/
errorHandler: errorHandler,

/**
* Axe API uses pino for logging.
*
* "pino-pretty" is a basic prettifier for Pino log lines. You don't have to
* use it in your project.
*
* @link https://getpino.io
* @link https://github.com/pinojs/pino-pretty
* @link https://axe-api.com/reference/pino-logger-configs.html
*/
pino: {
level: "debug",
level: process.env.LOG_LEVEL || "debug",
transport: {
target: "pino-pretty",
target: process.env.LOG_TRANSPORT || "pino-pretty",
},
},

/**
* Axe API uses knex.js for database operations. All of the database
* configurations are the same as the original documentation.
*
* @link https://axe-api.com/reference/database-configs.html
* @link https://knexjs.org/guide/#configuration-options
*/
database: {
client: process.env.DB_CLIENT || "mysql",
connection: {
Expand All @@ -31,6 +92,148 @@ const config: IApplicationConfig = {
tableName: "knex_migrations",
},
},

/**
* Axe API provides an internal rate limiter. You can set the rate limiter
* options here.
*
* @link https://axe-api.com/reference/rate-limit-configs.html
*/
rateLimit: {
/**
* The rate limiter can be enabled or disabled via the configuration item.
* It should be boolean.
*
* @link https://axe-api.com/reference/rate-limit-configs.html#enabled
*/
enabled: false,

/**
* The data storing adaptor. You can select memory or redis.
*
* @link https://axe-api.com/reference/rate-limit-configs.html#adaptor
*/
adaptor: "memory",

/**
* It is an option to be able to trust the X-Forwarded-For HTTP header
* value if the API is running behind a proxy server.
*
* The default value is false.
*
* @link https://axe-api.com/reference/rate-limit-configs.html#trustproxyip
*/
trustProxyIP: false,

/**
* The maximum acceptable request count during the time window for the
* generated key.
*
* @link https://axe-api.com/reference/rate-limit-configs.html#maxrequests
*/
maxRequests: 100,

/**
* The request time window. The value must be specified in seconds.
*
* @link https://axe-api.com/reference/rate-limit-configs.html#windowinseconds
*/
windowInSeconds: 10,
},

/**
* Axe API uses redis library to connect to the Redis to be able to manage
* Auto-caching and Rate limiting features.
*
* You can use the library's configuration.
*
* @link https://github.com/redis/node-redis/blob/HEAD/docs/client-configuration.md
* @link https://axe-api.com/reference/redis-configs.html
*/
redis: {},

/**
* Auto-caching feature configurations.
*
* @link https://axe-api.com/reference/cache-configs.html
* @link https://axe-api.com/learn/caching.html
*/
cache: {
/**
* You can use this configuration to enable or disable the auto-caching
* across all endpoints.
*
* @link https://axe-api.com/reference/cache-configs.html#enable
*/
enable: true,

/**
* The default invalidation time in seconds.
*
* @link https://axe-api.com/reference/cache-configs.html#ttl
*/
ttl: 300,

/**
* The cache invalidation strategy.
*
* @link https://axe-api.com/reference/cache-configs.html#invalidation
*/
invalidation: CacheStrategies.TagBased,

/**
* The cache prefix that used on all cache keys. You can use your
* application name.
*
* @link https://axe-api.com/reference/cache-configs.html#cacheprefix
*/
cachePrefix: "axe-api",

/**
* The tag prefix that used for all tagged items in `TagBased`
* invalidation strategies.
*
* @link https://axe-api.com/reference/cache-configs.html#tagprefix
*/
tagPrefix: "tag",

/**
* Axe API exposes the cache information in HTTP Response headers if it is
* Missed or Hit. You should set as NULL if you want to hide that information.
*
* @link https://axe-api.com/reference/cache-configs.html#responseheader
*/
responseHeader: "X-Axe-API-Cache",
},

/**
* Elasticsearch configuration for the Full-text search feature.
*
* @link https://axe-api.com/learn/full-text-search.html
* @link https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-configuration.html
*/
elasticSearch: {},

/**
* Axe API provides an full-text search configuration
*
* @link https://axe-api.com/reference/search-configs.html
*/
search: {
/**
* You can set a prefix for the model index name prefix.
*
* @link https://axe-api.com/reference/search-configs.html#indexprefix
*/
indexPrefix: "axe",
},

/**
* You can change the validator library.
*
* @link https://axe-api.com/blog/2024-02-18-axe-api-v1-is-out.html#supporting-robus-validator-library
*/
validator: "validatorjs",
};

export default config;
40 changes: 40 additions & 0 deletions app/v1/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
import { IVersionConfig, QueryFeature, allow } from "axe-api";

const config: IVersionConfig = {
/**
* The general database transaction configuration.
*
* @link https://axe-api.com/reference/version-configs.html#transactions
*/
transaction: [],

/**
* The general response serializers.
*
* @link https://axe-api.com/reference/version-configs.html#serializers
*/
serializers: [],

/**
* All supported languages by the API.
*
* @link https://axe-api.com/reference/version-configs.html#supportedlanguages
*/
supportedLanguages: ["en"],

/**
* The default language if the HTTP client doesn't specify any.
*
* @link https://axe-api.com/reference/version-configs.html#defaultlanguage
*/
defaultLanguage: "en",

/**
* The default Axe API Query Configurations.
*
* @link https://axe-api.com/reference/version-configs.html#query
*/
query: {
/**
* The query limits. You can decide which query features are enabled or not.
*
* @link https://axe-api.com/reference/version-configs.html#query-limits
*/
limits: [allow(QueryFeature.All)],

/**
* The default query parameters.
*
* @link https://axe-api.com/reference/version-configs.html#query-default
*/
defaults: {
perPage: 10,
minPerPage: 5,
Expand Down
Loading
Loading