@adonisjs/core
Advanced tools
Comparing version 2.7.5 to 2.8.0
/// <reference path="cors.d.ts" /> | ||
/// <reference path="health-check.d.ts" /> | ||
/// <reference path="exception-handler.d.ts" /> | ||
/// <reference path="static.d.ts" /> | ||
/// <reference types="@adonisjs/application/build/adonis-typings/application" /> | ||
@@ -5,0 +6,0 @@ /// <reference types="@adonisjs/config/build/adonis-typings/config" /> |
@@ -23,1 +23,2 @@ /* | ||
/// <reference path="./exception-handler.ts" /> | ||
/// <reference path="./static.ts" /> |
@@ -12,16 +12,32 @@ "use strict"; | ||
const path_1 = require("path"); | ||
const APP_TEMPLATE_STUB = path_1.join(__dirname, './config', 'app.txt'); | ||
const STATIC_TEMPLATE_STUB = path_1.join(__dirname, './config', 'static.txt'); | ||
async function instructions(projectRoot, application, { executeInstructions, TemplateFile, logger }) { | ||
const template = new TemplateFile(projectRoot, 'config/app.ts', path_1.join(__dirname, './config', 'app.txt')); | ||
if (template.exists()) { | ||
const isApiBoilerplate = process.env['ADONIS_CREATE_APP_BOILERPLATE'] === 'api'; | ||
/** | ||
* Create app config file | ||
*/ | ||
const appConfig = new TemplateFile(projectRoot, 'config/app.ts', APP_TEMPLATE_STUB); | ||
if (appConfig.exists()) { | ||
logger.skip('config/app.ts'); | ||
} | ||
else { | ||
template.apply({ | ||
forceContentNegotiationToJSON: process.env['ADONIS_CREATE_APP_BOILERPLATE'] === 'api' | ||
? true | ||
: false, | ||
}); | ||
template.commit(); | ||
appConfig.apply({ forceContentNegotiationToJSON: isApiBoilerplate }); | ||
appConfig.commit(); | ||
logger.create('config/app.ts'); | ||
} | ||
/** | ||
* Create static config file when boilerplate | ||
* is not for the api | ||
*/ | ||
if (!isApiBoilerplate) { | ||
const staticConfig = new TemplateFile(projectRoot, 'config/static.ts', STATIC_TEMPLATE_STUB); | ||
if (staticConfig.exists()) { | ||
logger.skip('config/static.ts'); | ||
} | ||
else { | ||
appConfig.apply({}).commit(); | ||
logger.create('config/static.ts'); | ||
} | ||
} | ||
await executeInstructions('@adonisjs/events', projectRoot, application); | ||
@@ -28,0 +44,0 @@ await executeInstructions('@adonisjs/hash', projectRoot, application); |
@@ -25,3 +25,11 @@ import { IocContract } from '@adonisjs/fold'; | ||
register(): void; | ||
/** | ||
* Lazy initialize the cors hook, if enabled inside the config | ||
*/ | ||
protected registerCorsHook(): void; | ||
/** | ||
* Lazy initialize the static assets hook, if enabled inside the config | ||
*/ | ||
protected registerStaticAssetsHook(): void; | ||
boot(): void; | ||
} |
@@ -11,3 +11,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Cors_1 = require("../src/Hooks/Cors"); | ||
const HealthCheck_1 = require("../src/HealthCheck"); | ||
@@ -59,11 +58,48 @@ const HttpExceptionHandler_1 = require("../src/HttpExceptionHandler"); | ||
} | ||
boot() { | ||
/** | ||
* Lazy initialize the cors hook, if enabled inside the config | ||
*/ | ||
registerCorsHook() { | ||
/** | ||
* Register the cors before hook with the server | ||
*/ | ||
this.$container.with(['Adonis/Core/Config', 'Adonis/Core/Server'], (Config, Server) => { | ||
Cors_1.serverHook(Server, Config.get('cors', {})); | ||
this.$container.with([ | ||
'Adonis/Core/Config', | ||
'Adonis/Core/Server', | ||
], (Config, Server) => { | ||
const config = Config.get('cors', {}); | ||
if (!config.enabled) { | ||
return; | ||
} | ||
const Cors = require('../src/Hooks/Cors').Cors; | ||
const cors = new Cors(config); | ||
Server.hooks.before(cors.handle.bind(cors)); | ||
}); | ||
} | ||
/** | ||
* Lazy initialize the static assets hook, if enabled inside the config | ||
*/ | ||
registerStaticAssetsHook() { | ||
/** | ||
* Register the cors before hook with the server | ||
*/ | ||
this.$container.with([ | ||
'Adonis/Core/Config', | ||
'Adonis/Core/Server', | ||
'Adonis/Core/Application', | ||
], (Config, Server, Application) => { | ||
const config = Config.get('static', {}); | ||
if (!config.enabled) { | ||
return; | ||
} | ||
const ServeStatic = require('../src/Hooks/Static').ServeStatic; | ||
const serveStatic = new ServeStatic(Application.publicPath(), config); | ||
Server.hooks.before(serveStatic.handle.bind(serveStatic)); | ||
}); | ||
} | ||
boot() { | ||
this.registerCorsHook(); | ||
this.registerStaticAssetsHook(); | ||
} | ||
} | ||
exports.default = AppProvider; |
@@ -0,4 +1,3 @@ | ||
import { CorsConfigContract } from '@ioc:Adonis/Core/Cors'; | ||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'; | ||
import { CorsConfigContract } from '@ioc:Adonis/Core/Cors'; | ||
import { ServerContract } from '@ioc:Adonis/Core/Server'; | ||
/** | ||
@@ -71,9 +70,1 @@ * The Cors middleware class to handle preflight request as per the CORS | ||
} | ||
/** | ||
* Exposes a function to bind the CORS class as a server before hook. | ||
* We only add the hook when `enabled` is set to true or a function. | ||
* | ||
* Since in most cases users will use a boolean value (true or false), | ||
* it is better not to add CORS to the stack when it's disabled. | ||
*/ | ||
export declare function serverHook(server: ServerContract, corsConfig: CorsConfigContract): void; |
@@ -314,15 +314,1 @@ "use strict"; | ||
exports.Cors = Cors; | ||
/** | ||
* Exposes a function to bind the CORS class as a server before hook. | ||
* We only add the hook when `enabled` is set to true or a function. | ||
* | ||
* Since in most cases users will use a boolean value (true or false), | ||
* it is better not to add CORS to the stack when it's disabled. | ||
*/ | ||
function serverHook(server, corsConfig) { | ||
if (corsConfig.enabled) { | ||
const cors = new Cors(corsConfig); | ||
server.hooks.before(cors.handle.bind(cors)); | ||
} | ||
} | ||
exports.serverHook = serverHook; |
{ | ||
"name": "@adonisjs/core", | ||
"version": "2.7.5", | ||
"version": "2.8.0", | ||
"description": "Adonisjs core", | ||
@@ -44,3 +44,3 @@ "main": "build/providers/AppProvider.js", | ||
"@adonisjs/assembler": "^1.2.7", | ||
"@adonisjs/fold": "^6.3.0", | ||
"@adonisjs/fold": "^6.3.1", | ||
"@adonisjs/mrm-preset": "^2.2.3", | ||
@@ -50,7 +50,7 @@ "@adonisjs/sink": "^2.4.3", | ||
"@types/ms": "^0.7.31", | ||
"@types/node": "^13.1.8", | ||
"@types/node": "^13.7.0", | ||
"@types/supertest": "^2.0.8", | ||
"commitizen": "^4.0.3", | ||
"copyfiles": "^2.2.0", | ||
"cz-conventional-changelog": "^3.0.2", | ||
"cz-conventional-changelog": "^3.1.0", | ||
"del-cli": "^3.0.0", | ||
@@ -60,5 +60,5 @@ "doctoc": "^1.4.0", | ||
"eslint-plugin-adonis": "^1.0.5", | ||
"husky": "^4.0.10", | ||
"husky": "^4.2.1", | ||
"japa": "^3.0.1", | ||
"mrm": "^2.0.2", | ||
"mrm": "^2.0.4", | ||
"np": "^5.2.1", | ||
@@ -111,2 +111,3 @@ "proxy-addr": "^2.0.5", | ||
"on-finished": "^2.3.0", | ||
"serve-static": "^1.14.1", | ||
"simple-encryptor": "^3.0.0" | ||
@@ -113,0 +114,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103050
49
2591
22
+ Addedserve-static@^1.14.1
+ Addeddebug@2.6.9(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addedencodeurl@2.0.0(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedsend@0.19.0(transitive)
+ Addedserve-static@1.16.2(transitive)
+ Addedstatuses@2.0.1(transitive)