mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
chore: add adonis 5 boilerplate
This commit is contained in:
parent
9879146433
commit
cdabe6a2ca
22 changed files with 5421 additions and 0 deletions
26
server-new/.adonisrc.json
Normal file
26
server-new/.adonisrc.json
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"typescript": true,
|
||||||
|
"commands": [
|
||||||
|
"./commands",
|
||||||
|
"@adonisjs/core/build/commands"
|
||||||
|
],
|
||||||
|
"exceptionHandlerNamespace": "App/Exceptions/Handler",
|
||||||
|
"aliases": {
|
||||||
|
"App": "app",
|
||||||
|
"Contracts": "contracts",
|
||||||
|
"Config": "config",
|
||||||
|
"Database": "database"
|
||||||
|
},
|
||||||
|
"preloads": [
|
||||||
|
"./start/routes",
|
||||||
|
"./start/kernel"
|
||||||
|
],
|
||||||
|
"providers": [
|
||||||
|
"./providers/AppProvider",
|
||||||
|
"@adonisjs/core"
|
||||||
|
],
|
||||||
|
"metaFiles": [
|
||||||
|
".env",
|
||||||
|
".adonisrc.json"
|
||||||
|
]
|
||||||
|
}
|
||||||
14
server-new/.editorconfig
Normal file
14
server-new/.editorconfig
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.json]
|
||||||
|
insert_final_newline = ignore
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
4
server-new/.env.example
Normal file
4
server-new/.env.example
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
PORT=
|
||||||
|
HOST=
|
||||||
|
NODE_ENV=
|
||||||
|
APP_KEY=
|
||||||
1
server-new/.eslintignore
Normal file
1
server-new/.eslintignore
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
build
|
||||||
5
server-new/.eslintrc.json
Normal file
5
server-new/.eslintrc.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"plugin:adonis/typescriptApp"
|
||||||
|
]
|
||||||
|
}
|
||||||
7
server-new/.gitignore
vendored
Normal file
7
server-new/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
node_modules
|
||||||
|
build
|
||||||
|
coverage
|
||||||
|
.vscode
|
||||||
|
.DS_STORE
|
||||||
|
.env
|
||||||
|
tmp
|
||||||
19
server-new/ace
Normal file
19
server-new/ace
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Ace Commands
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This file is the entry point for running ace commands. For typescript
|
||||||
|
| projects, the ace commands will fallback to the compiled code and
|
||||||
|
| hence this file has to be executable by node directly.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
require('reflect-metadata')
|
||||||
|
require('source-map-support').install({ handleUncaughtExceptions: false })
|
||||||
|
|
||||||
|
const { Ignitor } = require('@adonisjs/core/build/src/Ignitor')
|
||||||
|
new Ignitor(__dirname)
|
||||||
|
.ace()
|
||||||
|
.handle(process.argv.slice(2))
|
||||||
|
.catch(console.error)
|
||||||
23
server-new/app/Exceptions/Handler.ts
Normal file
23
server-new/app/Exceptions/Handler.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Http Exception Handler
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| AdonisJs will forward all exceptions occurred during an HTTP request to
|
||||||
|
| the following class. You can learn more about exception handling by
|
||||||
|
| reading docs.
|
||||||
|
|
|
||||||
|
| The exception handler extends a base `HttpExceptionHandler` which is not
|
||||||
|
| mandatory, however it can do lot of heavy lifting to handle the errors
|
||||||
|
| properly.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Logger from '@ioc:Adonis/Core/Logger'
|
||||||
|
import HttpExceptionHandler from '@ioc:Adonis/Core/HttpExceptionHandler'
|
||||||
|
|
||||||
|
export default class ExceptionHandler extends HttpExceptionHandler {
|
||||||
|
constructor () {
|
||||||
|
super(Logger)
|
||||||
|
}
|
||||||
|
}
|
||||||
19
server-new/commands/index.ts
Normal file
19
server-new/commands/index.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { listDirectoryFiles } from '@adonisjs/ace'
|
||||||
|
import Application from '@ioc:Adonis/Core/Application'
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Exporting an array of commands
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Instead of manually exporting each file from this directory, we use the
|
||||||
|
| helper `listDirectoryFiles` to recursively collect and export an array
|
||||||
|
| of filenames.
|
||||||
|
|
|
||||||
|
| Couple of things to note:
|
||||||
|
|
|
||||||
|
| 1. The file path must be relative from the project root and not this directory.
|
||||||
|
| 2. We must ignore this file.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
export default listDirectoryFiles(__dirname, Application.appRoot, ['./commands/index.js'])
|
||||||
225
server-new/config/app.ts
Normal file
225
server-new/config/app.ts
Normal file
|
|
@ -0,0 +1,225 @@
|
||||||
|
/**
|
||||||
|
* Config source: https://git.io/JfefZ
|
||||||
|
*
|
||||||
|
* Feel free to let us know via PR, if you find something broken in this config
|
||||||
|
* file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import proxyAddr from 'proxy-addr'
|
||||||
|
import Env from '@ioc:Adonis/Core/Env'
|
||||||
|
import { LoggerConfig } from '@ioc:Adonis/Core/Logger'
|
||||||
|
import { RequestConfig } from '@ioc:Adonis/Core/Request'
|
||||||
|
import { ResponseConfig } from '@ioc:Adonis/Core/Response'
|
||||||
|
import { ProfilerConfig } from '@ioc:Adonis/Core/Profiler'
|
||||||
|
|
||||||
|
type HttpConfig = RequestConfig & ResponseConfig
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application secret key
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The secret to encrypt and sign different values in your application.
|
||||||
|
| Make sure to keep the `APP_KEY` as an environment variable and secure.
|
||||||
|
|
|
||||||
|
| Note: Changing the application key for an existing app will make all
|
||||||
|
| the cookies invalid and also the existing encrypted data will not
|
||||||
|
| be decrypted.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
export const appKey: string = Env.getOrFail('APP_KEY') as string
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Http server configuration
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The configuration for the HTTP(s) server. Make sure to go through all
|
||||||
|
| the config properties to make keep server secure.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
export const http: HttpConfig = {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Allow method spoofing
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Method spoofing enables defining custom HTTP methods using a query string
|
||||||
|
| `_method`. This is usually required when you are making traditional
|
||||||
|
| form requests and wants to use HTTP verbs like `PUT`, `DELETE` and
|
||||||
|
| so on.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
allowMethodSpoofing: false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Subdomain offset
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
subdomainOffset: 2,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Request Ids
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Setting this value to `true` will generate a unique request id for each
|
||||||
|
| HTTP request and set it as `x-request-id` header.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
generateRequestId: false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Trusting proxy servers
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Define the proxy servers that AdonisJs must trust for reading `X-Forwarded`
|
||||||
|
| headers.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
trustProxy: proxyAddr.compile('loopback'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Generating Etag
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Whether or not to generate an etag for every response.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
etag: false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| JSONP Callback
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
jsonpCallbackName: 'callback',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Cookie settings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
cookie: {
|
||||||
|
domain: '',
|
||||||
|
path: '/',
|
||||||
|
maxAge: '2h',
|
||||||
|
httpOnly: true,
|
||||||
|
secure: false,
|
||||||
|
sameSite: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Force content negotiation to JSON
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The internals of the framework relies on the content negotiation to
|
||||||
|
| detect the best possible response type for a given HTTP request.
|
||||||
|
|
|
||||||
|
| However, it is a very common these days that API servers always wants to
|
||||||
|
| make response in JSON regardless of the existence of the `Accept` header.
|
||||||
|
|
|
||||||
|
| By setting `forceContentNegotiationToJSON = true`, you negotiate with the
|
||||||
|
| server in advance to always return JSON without relying on the client
|
||||||
|
| to set the header explicitly.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
forceContentNegotiationToJSON: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Logger
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
export const logger: LoggerConfig = {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application name
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The name of the application you want to add to the log. It is recommended
|
||||||
|
| to always have app name in every log line.
|
||||||
|
|
|
||||||
|
| The `APP_NAME` environment variable is automatically set by AdonisJS by
|
||||||
|
| reading the `name` property from the `package.json` file.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
name: Env.get('APP_NAME') as string,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Toggle logger
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Enable or disable logger application wide
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
enabled: true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Logging level
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The level from which you want the logger to flush logs. It is recommended
|
||||||
|
| to make use of the environment variable, so that you can define log levels
|
||||||
|
| at deployment level and not code level.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
level: Env.get('LOG_LEVEL', 'info') as string,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Pretty print
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| It is highly advised NOT to use `prettyPrint` in production, since it
|
||||||
|
| can have huge impact on performance.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
prettyPrint: Env.get('NODE_ENV') === 'development',
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Profiler
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
export const profiler: ProfilerConfig = {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Toggle profiler
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Enable or disable profiler
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
enabled: true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Blacklist actions/row labels
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Define an array of actions or row labels that you want to disable from
|
||||||
|
| getting profiled.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
blacklist: [],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Whitelist actions/row labels
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Define an array of actions or row labels that you want to whitelist for
|
||||||
|
| the profiler. When whitelist is defined, then `blacklist` is ignored.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
whitelist: [],
|
||||||
|
}
|
||||||
186
server-new/config/bodyparser.ts
Normal file
186
server-new/config/bodyparser.ts
Normal file
|
|
@ -0,0 +1,186 @@
|
||||||
|
/**
|
||||||
|
* Config source: https://git.io/Jfefn
|
||||||
|
*
|
||||||
|
* Feel free to let us know via PR, if you find something broken in this config
|
||||||
|
* file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { BodyParserConfig } from '@ioc:Adonis/Core/BodyParser'
|
||||||
|
|
||||||
|
const bodyParserConfig: BodyParserConfig = {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| White listed methods
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| HTTP methods for which body parsing must be performed. It is a good practice
|
||||||
|
| to avoid body parsing for `GET` requests.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
whitelistedMethods: ['POST', 'PUT', 'PATCH', 'DELETE'],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| JSON parser settings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The settings for the JSON parser. The types defines the request content
|
||||||
|
| types which gets processed by the JSON parser.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
json: {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
limit: '1mb',
|
||||||
|
strict: true,
|
||||||
|
types: [
|
||||||
|
'application/json',
|
||||||
|
'application/json-patch+json',
|
||||||
|
'application/vnd.api+json',
|
||||||
|
'application/csp-report',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Form parser settings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The settings for the `application/x-www-form-urlencoded` parser. The types
|
||||||
|
| defines the request content types which gets processed by the form parser.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
form: {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
limit: '1mb',
|
||||||
|
queryString: {},
|
||||||
|
types: [
|
||||||
|
'application/x-www-form-urlencoded',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Raw body parser settings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Raw body just reads the request body stream as a plain text, which you
|
||||||
|
| can process by hand. This must be used when request body type is not
|
||||||
|
| supported by the body parser.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
raw: {
|
||||||
|
encoding: 'utf-8',
|
||||||
|
limit: '1mb',
|
||||||
|
queryString: {},
|
||||||
|
types: [
|
||||||
|
'text/*',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Multipart parser settings
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The settings for the `multipart/form-data` parser. The types defines the
|
||||||
|
| request content types which gets processed by the form parser.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
multipart: {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Auto process
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The auto process option will process uploaded files and writes them to
|
||||||
|
| the `tmp` folder. You can turn it off and then manually use the stream
|
||||||
|
| to pipe stream to a different destination.
|
||||||
|
|
|
||||||
|
| It is recommended to keep `autoProcess=true`. Unless you are processing bigger
|
||||||
|
| file sizes.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
autoProcess: true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Files to be processed manually
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| You can turn off `autoProcess` for certain routes by defining
|
||||||
|
| routes inside the following array.
|
||||||
|
|
|
||||||
|
| NOTE: Make sure the route pattern starts with a leading slash.
|
||||||
|
|
|
||||||
|
| Correct
|
||||||
|
| ```js
|
||||||
|
| /projects/:id/file
|
||||||
|
| ```
|
||||||
|
|
|
||||||
|
| Incorrect
|
||||||
|
| ```js
|
||||||
|
| projects/:id/file
|
||||||
|
| ```
|
||||||
|
*/
|
||||||
|
processManually: [],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Temporary file name
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| When auto processing is on. We will use this method to compute the temporary
|
||||||
|
| file name. AdonisJs will compute a unique `tmpPath` for you automatically,
|
||||||
|
| However, you can also define your own custom method.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
// tmpFileName () {
|
||||||
|
// },
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Encoding
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Request body encoding
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
encoding: 'utf-8',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Max Fields
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The maximum number of fields allowed in the request body. The field includes
|
||||||
|
| text inputs and files both.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
maxFields: 1000,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Request body limit
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The total limit to the multipart body. This includes all request files
|
||||||
|
| and fields data.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
limit: '20mb',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Types
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The types that will be considered and parsed as multipart body.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
types: [
|
||||||
|
'multipart/form-data',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default bodyParserConfig
|
||||||
134
server-new/config/cors.ts
Normal file
134
server-new/config/cors.ts
Normal file
|
|
@ -0,0 +1,134 @@
|
||||||
|
/**
|
||||||
|
* Config source: https://git.io/JfefC
|
||||||
|
*
|
||||||
|
* Feel free to let us know via PR, if you find something broken in this config
|
||||||
|
* file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CorsConfig } from '@ioc:Adonis/Core/Cors'
|
||||||
|
|
||||||
|
const corsConfig: CorsConfig = {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Enabled
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| A boolean to enable or disable CORS integration from your AdonisJs
|
||||||
|
| application.
|
||||||
|
|
|
||||||
|
| Setting the value to `true` will enable the CORS for all HTTP request. However,
|
||||||
|
| you can define a function to enable/disable it on per request basis as well.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
enabled: true,
|
||||||
|
|
||||||
|
// You can also use a function that return true or false.
|
||||||
|
// enabled: (request) => request.url().startsWith('/api')
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Origin
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Set a list of origins to be allowed for `Access-Control-Allow-Origin`.
|
||||||
|
| The value can be one of the following:
|
||||||
|
|
|
||||||
|
| https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
|
||||||
|
|
|
||||||
|
| Boolean (true) - Allow current request origin.
|
||||||
|
| Boolean (false) - Disallow all.
|
||||||
|
| String - Comma separated list of allowed origins.
|
||||||
|
| Array - An array of allowed origins.
|
||||||
|
| String (*) - A wildcard (*) to allow all request origins.
|
||||||
|
| Function - Receives the current origin string and should return
|
||||||
|
| one of the above values.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
origin: true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Methods
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| An array of allowed HTTP methods for CORS. The `Access-Control-Request-Method`
|
||||||
|
| is checked against the following list.
|
||||||
|
|
|
||||||
|
| Following is the list of default methods. Feel free to add more.
|
||||||
|
*/
|
||||||
|
methods: ['GET', 'HEAD', 'POST', 'PUT', 'DELETE'],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Headers
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| List of headers to be allowed for `Access-Control-Allow-Headers` header.
|
||||||
|
| The value can be one of the following:
|
||||||
|
|
|
||||||
|
| https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers
|
||||||
|
|
|
||||||
|
| Boolean(true) - Allow all headers mentioned in `Access-Control-Request-Headers`.
|
||||||
|
| Boolean(false) - Disallow all headers.
|
||||||
|
| String - Comma separated list of allowed headers.
|
||||||
|
| Array - An array of allowed headers.
|
||||||
|
| Function - Receives the current header and should return one of the above values.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
headers: true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Expose Headers
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| A list of headers to be exposed by setting `Access-Control-Expose-Headers`.
|
||||||
|
| header. By default following 6 simple response headers are exposed.
|
||||||
|
|
|
||||||
|
| Cache-Control
|
||||||
|
| Content-Language
|
||||||
|
| Content-Type
|
||||||
|
| Expires
|
||||||
|
| Last-Modified
|
||||||
|
| Pragma
|
||||||
|
|
|
||||||
|
| In order to add more headers, simply define them inside the following array.
|
||||||
|
|
|
||||||
|
| https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
exposeHeaders: [
|
||||||
|
'cache-control',
|
||||||
|
'content-language',
|
||||||
|
'content-type',
|
||||||
|
'expires',
|
||||||
|
'last-modified',
|
||||||
|
'pragma',
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Credentials
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Toggle `Access-Control-Allow-Credentials` header. If value is set to `true`,
|
||||||
|
| then header will be set, otherwise not.
|
||||||
|
|
|
||||||
|
| https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
credentials: true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| MaxAge
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Define `Access-Control-Max-Age` header in seconds.
|
||||||
|
| https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
maxAge: 90,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default corsConfig
|
||||||
75
server-new/config/hash.ts
Normal file
75
server-new/config/hash.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
* Config source: https://git.io/JfefW
|
||||||
|
*
|
||||||
|
* Feel free to let us know via PR, if you find something broken in this config
|
||||||
|
* file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Env from '@ioc:Adonis/Core/Env'
|
||||||
|
import { HashConfig } from '@ioc:Adonis/Core/Hash'
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Hash Config
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The `HashConfig` relies on the `HashList` interface which is
|
||||||
|
| defined inside `contracts` directory.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
const hashConfig: HashConfig = {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Default hasher
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| By default we make use of the bcrypt hasher to hash values. However, feel
|
||||||
|
| free to change the default value
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
default: Env.get('HASH_DRIVER', 'argon') as 'argon',
|
||||||
|
|
||||||
|
list: {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Argon
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Argon mapping uses the `argon2` driver to hash values.
|
||||||
|
|
|
||||||
|
| Make sure you install the underlying dependency for this driver to work.
|
||||||
|
| https://www.npmjs.com/package/phc-argon2.
|
||||||
|
|
|
||||||
|
| npm install phc-argon2
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
argon: {
|
||||||
|
driver: 'argon2',
|
||||||
|
variant: 'id',
|
||||||
|
iterations: 3,
|
||||||
|
memory: 4096,
|
||||||
|
parallelism: 1,
|
||||||
|
saltSize: 16,
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Bcrypt
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Bcrypt mapping uses the `bcrypt` driver to hash values.
|
||||||
|
|
|
||||||
|
| Make sure you install the underlying dependency for this driver to work.
|
||||||
|
| https://www.npmjs.com/package/phc-bcrypt.
|
||||||
|
|
|
||||||
|
| npm install phc-bcrypt
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
bcrypt: {
|
||||||
|
driver: 'bcrypt',
|
||||||
|
rounds: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default hashConfig
|
||||||
30
server-new/contracts/events.ts
Normal file
30
server-new/contracts/events.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
* Contract source: https://git.io/JfefG
|
||||||
|
*
|
||||||
|
* Feel free to let us know via PR, if you find something broken in this contract
|
||||||
|
* file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module '@ioc:Adonis/Core/Event' {
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Define typed events
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| You can define types for events inside the following interface and
|
||||||
|
| AdonisJS will make sure that all listeners and emit calls adheres
|
||||||
|
| to the defined types.
|
||||||
|
|
|
||||||
|
| For example:
|
||||||
|
|
|
||||||
|
| interface EventsList {
|
||||||
|
| 'new:user': UserModel
|
||||||
|
| }
|
||||||
|
|
|
||||||
|
| Now calling `Event.emit('new:user')` will statically ensure that passed value is
|
||||||
|
| an instance of the the UserModel only.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
interface EventsList {
|
||||||
|
}
|
||||||
|
}
|
||||||
21
server-new/contracts/hash.ts
Normal file
21
server-new/contracts/hash.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* Contract source: https://git.io/Jfefs
|
||||||
|
*
|
||||||
|
* Feel free to let us know via PR, if you find something broken in this contract
|
||||||
|
* file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module '@ioc:Adonis/Core/Hash' {
|
||||||
|
import { HashDrivers } from '@ioc:Adonis/Core/Hash'
|
||||||
|
|
||||||
|
interface HashersList {
|
||||||
|
bcrypt: {
|
||||||
|
config: BcryptConfig,
|
||||||
|
implementation: BcryptContract,
|
||||||
|
},
|
||||||
|
argon: {
|
||||||
|
config: ArgonConfig,
|
||||||
|
implementation: ArgonContract,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
4461
server-new/package-lock.json
generated
Normal file
4461
server-new/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
29
server-new/package.json
Normal file
29
server-new/package.json
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"name": "leaguestats-api",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build": "node ace build",
|
||||||
|
"dev": "npm run start",
|
||||||
|
"start": "node ace serve --watch",
|
||||||
|
"lint": "eslint . --ext=.ts"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@adonisjs/assembler": "^2.1.5",
|
||||||
|
"adonis-preset-ts": "^1.0.4",
|
||||||
|
"eslint": "^7.10.0",
|
||||||
|
"eslint-plugin-adonis": "^1.0.15",
|
||||||
|
"pino-pretty": "^4.2.1",
|
||||||
|
"typescript": "^4.0.3",
|
||||||
|
"youch": "^2.1.0",
|
||||||
|
"youch-terminal": "^1.0.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@adonisjs/ace": "^6.9.4",
|
||||||
|
"@adonisjs/core": "^5.0.0-preview-rc-1.12",
|
||||||
|
"@adonisjs/fold": "^6.4.1",
|
||||||
|
"proxy-addr": "^2.0.6",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"source-map-support": "^0.5.19"
|
||||||
|
}
|
||||||
|
}
|
||||||
22
server-new/providers/AppProvider.ts
Normal file
22
server-new/providers/AppProvider.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { IocContract } from '@adonisjs/fold'
|
||||||
|
|
||||||
|
export default class AppProvider {
|
||||||
|
constructor (protected $container: IocContract) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public register () {
|
||||||
|
// Register your own bindings
|
||||||
|
}
|
||||||
|
|
||||||
|
public boot () {
|
||||||
|
// IoC container is ready
|
||||||
|
}
|
||||||
|
|
||||||
|
public shutdown () {
|
||||||
|
// Cleanup, since app is going down
|
||||||
|
}
|
||||||
|
|
||||||
|
public ready () {
|
||||||
|
// App is ready
|
||||||
|
}
|
||||||
|
}
|
||||||
22
server-new/server.ts
Normal file
22
server-new/server.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| AdonisJs Server
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The contents in this file is meant to bootstrap the AdonisJs application
|
||||||
|
| and start the HTTP server to accept incoming connections. You must avoid
|
||||||
|
| making this file dirty and instead make use of `lifecycle hooks` provided
|
||||||
|
| by AdonisJs service providers for custom code.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import 'reflect-metadata'
|
||||||
|
import sourceMapSupport from 'source-map-support'
|
||||||
|
import { Ignitor } from '@adonisjs/core/build/src/Ignitor'
|
||||||
|
|
||||||
|
sourceMapSupport.install({ handleUncaughtExceptions: false })
|
||||||
|
|
||||||
|
new Ignitor(__dirname)
|
||||||
|
.httpServer()
|
||||||
|
.start()
|
||||||
|
.catch(console.error)
|
||||||
44
server-new/start/kernel.ts
Normal file
44
server-new/start/kernel.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Application middleware
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This file is used to define middleware for HTTP requests. You can register
|
||||||
|
| middleware as a `closure` or an IoC container binding. The bindings are
|
||||||
|
| preferred, since they keep this file clean.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Server from '@ioc:Adonis/Core/Server'
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Global middleware
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| An array of global middleware, that will be executed in the order they
|
||||||
|
| are defined for all HTTP requests.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
Server.middleware.register([
|
||||||
|
'Adonis/Core/BodyParserMiddleware',
|
||||||
|
])
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Named middleware
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Named middleware are defined a key-value pair. The value is the namespace
|
||||||
|
| or middleware function and key is the alias. Later you can use these
|
||||||
|
| alias on individual routes. For example:
|
||||||
|
|
|
||||||
|
| { auth: 'Adonis/Auth/Middleware' }
|
||||||
|
|
|
||||||
|
| and then use it as follows
|
||||||
|
|
|
||||||
|
| Route.get('dashboard', 'UserController.dashboard').middleware('auth')
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
Server.middleware.registerNamed({
|
||||||
|
})
|
||||||
25
server-new/start/routes.ts
Normal file
25
server-new/start/routes.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Routes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This file is dedicated for defining HTTP routes. A single file is enough
|
||||||
|
| for majority of projects, however you can define routes in different
|
||||||
|
| files and just make sure to import them inside this file. For example
|
||||||
|
|
|
||||||
|
| Define routes in following two files
|
||||||
|
| ├── start/routes/cart.ts
|
||||||
|
| ├── start/routes/customer.ts
|
||||||
|
|
|
||||||
|
| and then import them inside `start/routes/index.ts` as follows
|
||||||
|
|
|
||||||
|
| import './cart'
|
||||||
|
| import './customer'
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Route from '@ioc:Adonis/Core/Route'
|
||||||
|
|
||||||
|
Route.get('/', async () => {
|
||||||
|
return { hello: 'world' }
|
||||||
|
})
|
||||||
29
server-new/tsconfig.json
Normal file
29
server-new/tsconfig.json
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"include": [
|
||||||
|
"**/*"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"build"
|
||||||
|
],
|
||||||
|
"extends": "./node_modules/adonis-preset-ts/tsconfig",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "build",
|
||||||
|
"rootDir": "./",
|
||||||
|
"sourceMap": true,
|
||||||
|
"paths": {
|
||||||
|
"App/*": [
|
||||||
|
"./app/*"
|
||||||
|
],
|
||||||
|
"Contracts/*": [
|
||||||
|
"./contracts/*"
|
||||||
|
],
|
||||||
|
"Database/*": [
|
||||||
|
"./database/*"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"types": [
|
||||||
|
"@adonisjs/core"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue