comm
parent
c7cf60b529
commit
55a0040734
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"extends": "@hapi/eslint-config-hapi",
|
"extends": "@hapi/eslint-config-hapi",
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2020,
|
"ecmaVersion": 2020,
|
||||||
"sourceType": "script"
|
"sourceType": "script"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
server/.env
|
server/.env
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
*
|
*
|
||||||
!lib/**
|
!lib/**
|
||||||
|
|
42
knexfile.js
42
knexfile.js
|
@ -1,21 +1,21 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Path = require('path');
|
const Path = require('path');
|
||||||
const Hoek = require('@hapi/hoek');
|
const Hoek = require('@hapi/hoek');
|
||||||
const Manifest = require('./server/manifest');
|
const Manifest = require('./server/manifest');
|
||||||
const Plugin = require('./lib/plugins/@hapipal.schwifty');
|
const Plugin = require('./lib/plugins/@hapipal.schwifty');
|
||||||
|
|
||||||
// Take schwifty registration's knex option
|
// Take schwifty registration's knex option
|
||||||
// but specify the plugin's migrations directory
|
// but specify the plugin's migrations directory
|
||||||
|
|
||||||
module.exports = Hoek.applyToDefaults(
|
module.exports = Hoek.applyToDefaults(
|
||||||
{
|
{
|
||||||
migrations: {
|
migrations: {
|
||||||
directory: Path.relative(process.cwd(), Plugin.options.migrationsDir)
|
directory: Path.relative(process.cwd(), Plugin.options.migrationsDir)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Manifest
|
Manifest
|
||||||
.get('/register/plugins', process.env)
|
.get('/register/plugins', process.env)
|
||||||
.find(({ plugin }) => plugin === '@hapipal/schwifty')
|
.find(({ plugin }) => plugin === '@hapipal/schwifty')
|
||||||
.options.knex
|
.options.knex
|
||||||
);
|
);
|
||||||
|
|
28
lib/index.js
28
lib/index.js
|
@ -1,14 +1,14 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const HauteCouture = require('@hapipal/haute-couture');
|
const HauteCouture = require('@hapipal/haute-couture');
|
||||||
const Package = require('../package.json');
|
const Package = require('../package.json');
|
||||||
|
|
||||||
exports.plugin = {
|
exports.plugin = {
|
||||||
pkg: Package,
|
pkg: Package,
|
||||||
register: async (server, options) => {
|
register: async (server, options) => {
|
||||||
|
|
||||||
// Custom plugin code can go here
|
// Custom plugin code can go here
|
||||||
|
|
||||||
await HauteCouture.compose(server, options);
|
await HauteCouture.compose(server, options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
options: {
|
options: {
|
||||||
migrationsDir: `${__dirname}/../migrations`
|
migrationsDir: `${__dirname}/../migrations`
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/user',
|
path: '/user',
|
||||||
options: { },
|
options: { },
|
||||||
handler: async (request, h) => {
|
handler: async (request, h) => {
|
||||||
|
|
||||||
return { firstName: 'John', lastName: 'Doe'};
|
return { firstName: 'John', lastName: 'Doe'};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
98
package.json
98
package.json
|
@ -1,49 +1,49 @@
|
||||||
{
|
{
|
||||||
"name": "iut-project-cemal",
|
"name": "iut-project-cemal",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib",
|
"lib": "lib",
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server",
|
"start": "node server",
|
||||||
"test": "lab -a @hapi/code -I \"__core-js_shared__,CSS,regeneratorRuntime,core\" -L",
|
"test": "lab -a @hapi/code -I \"__core-js_shared__,CSS,regeneratorRuntime,core\" -L",
|
||||||
"lint": "eslint ."
|
"lint": "eslint ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hapi/boom": "9.x.x",
|
"@hapi/boom": "9.x.x",
|
||||||
"@hapipal/haute-couture": "4.x.x",
|
"@hapipal/haute-couture": "4.x.x",
|
||||||
"joi": "17.x.x",
|
"joi": "17.x.x",
|
||||||
"objection": "2.x.x",
|
"objection": "2.x.x",
|
||||||
"@hapipal/schwifty": "6.x.x",
|
"@hapipal/schwifty": "6.x.x",
|
||||||
"sqlite3": "5.0.2",
|
"sqlite3": "5.0.2",
|
||||||
"exiting": "6.0.1"
|
"exiting": "6.0.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"knex": "0.21.x"
|
"knex": "0.21.x"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@hapi/code": "8.x.x",
|
"@hapi/code": "8.x.x",
|
||||||
"@hapi/eslint-config-hapi": "13.x.x",
|
"@hapi/eslint-config-hapi": "13.x.x",
|
||||||
"@hapi/eslint-plugin-hapi": "4.x.x",
|
"@hapi/eslint-plugin-hapi": "4.x.x",
|
||||||
"@hapi/glue": "8.x.x",
|
"@hapi/glue": "8.x.x",
|
||||||
"@hapi/hapi": "20.x.x",
|
"@hapi/hapi": "20.x.x",
|
||||||
"@hapi/hoek": "9.x.x",
|
"@hapi/hoek": "9.x.x",
|
||||||
"@hapi/inert": "6.x.x",
|
"@hapi/inert": "6.x.x",
|
||||||
"@hapi/lab": "23.x.x",
|
"@hapi/lab": "23.x.x",
|
||||||
"@hapi/vision": "6.x.x",
|
"@hapi/vision": "6.x.x",
|
||||||
"babel-eslint": "10.x.x",
|
"babel-eslint": "10.x.x",
|
||||||
"@hapipal/confidence": "6.x.x",
|
"@hapipal/confidence": "6.x.x",
|
||||||
"dotenv": "8.x.x",
|
"dotenv": "8.x.x",
|
||||||
"eslint": "7.x.x",
|
"eslint": "7.x.x",
|
||||||
"hapi-swagger": "14.x.x",
|
"hapi-swagger": "14.x.x",
|
||||||
"@hapipal/hpal": "3.x.x",
|
"@hapipal/hpal": "3.x.x",
|
||||||
"@hapipal/hpal-debug": "2.x.x",
|
"@hapipal/hpal-debug": "2.x.x",
|
||||||
"knex": "^0.21.16",
|
"knex": "^0.21.16",
|
||||||
"@hapipal/toys": "3.x.x"
|
"@hapipal/toys": "3.x.x"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Rename me to .env then fill me with runtime configuration and credentials
|
# Rename me to .env then fill me with runtime configuration and credentials
|
||||||
# Just don't try to check me into your repo :)
|
# Just don't try to check me into your repo :)
|
||||||
# Confused? See https://github.com/motdotla/dotenv
|
# Confused? See https://github.com/motdotla/dotenv
|
||||||
#
|
#
|
||||||
# e.g.
|
# e.g.
|
||||||
# PORT=4000
|
# PORT=4000
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Glue = require('@hapi/glue');
|
const Glue = require('@hapi/glue');
|
||||||
const Exiting = require('exiting');
|
const Exiting = require('exiting');
|
||||||
const Manifest = require('./manifest');
|
const Manifest = require('./manifest');
|
||||||
|
|
||||||
exports.deployment = async ({ start } = {}) => {
|
exports.deployment = async ({ start } = {}) => {
|
||||||
|
|
||||||
const manifest = Manifest.get('/', process.env);
|
const manifest = Manifest.get('/', process.env);
|
||||||
const server = await Glue.compose(manifest, { relativeTo: __dirname });
|
const server = await Glue.compose(manifest, { relativeTo: __dirname });
|
||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
await Exiting.createManager(server).start();
|
await Exiting.createManager(server).start();
|
||||||
server.log(['start'], `Server started at ${server.info.uri}`);
|
server.log(['start'], `Server started at ${server.info.uri}`);
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
await server.initialize();
|
await server.initialize();
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
|
||||||
exports.deployment({ start: true });
|
exports.deployment({ start: true });
|
||||||
|
|
||||||
process.on('unhandledRejection', (err) => {
|
process.on('unhandledRejection', (err) => {
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,72 +1,72 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Dotenv = require('dotenv');
|
const Dotenv = require('dotenv');
|
||||||
const Confidence = require('@hapipal/confidence');
|
const Confidence = require('@hapipal/confidence');
|
||||||
const Toys = require('@hapipal/toys');
|
const Toys = require('@hapipal/toys');
|
||||||
const Schwifty = require('@hapipal/schwifty');
|
const Schwifty = require('@hapipal/schwifty');
|
||||||
|
|
||||||
// Pull .env into process.env
|
// Pull .env into process.env
|
||||||
Dotenv.config({ path: `${__dirname}/.env` });
|
Dotenv.config({ path: `${__dirname}/.env` });
|
||||||
|
|
||||||
// Glue manifest as a confidence store
|
// Glue manifest as a confidence store
|
||||||
module.exports = new Confidence.Store({
|
module.exports = new Confidence.Store({
|
||||||
server: {
|
server: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: {
|
port: {
|
||||||
$env: 'PORT',
|
$env: 'PORT',
|
||||||
$coerce: 'number',
|
$coerce: 'number',
|
||||||
$default: 3000
|
$default: 3000
|
||||||
},
|
},
|
||||||
debug: {
|
debug: {
|
||||||
$filter: { $env: 'NODE_ENV' },
|
$filter: { $env: 'NODE_ENV' },
|
||||||
$default: {
|
$default: {
|
||||||
log: ['error'],
|
log: ['error'],
|
||||||
request: ['error']
|
request: ['error']
|
||||||
},
|
},
|
||||||
production: {
|
production: {
|
||||||
request: ['implementation']
|
request: ['implementation']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
register: {
|
register: {
|
||||||
plugins: [
|
plugins: [
|
||||||
{
|
{
|
||||||
plugin: '../lib', // Main plugin
|
plugin: '../lib', // Main plugin
|
||||||
options: {}
|
options: {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
plugin: './plugins/swagger'
|
plugin: './plugins/swagger'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
plugin: '@hapipal/schwifty',
|
plugin: '@hapipal/schwifty',
|
||||||
options: {
|
options: {
|
||||||
$filter: 'NODE_ENV',
|
$filter: 'NODE_ENV',
|
||||||
$default: {},
|
$default: {},
|
||||||
$base: {
|
$base: {
|
||||||
migrateOnStart: true,
|
migrateOnStart: true,
|
||||||
knex: {
|
knex: {
|
||||||
client: 'sqlite3',
|
client: 'sqlite3',
|
||||||
useNullAsDefault: true, // Suggested for sqlite3
|
useNullAsDefault: true, // Suggested for sqlite3
|
||||||
connection: {
|
connection: {
|
||||||
filename: ':memory:'
|
filename: ':memory:'
|
||||||
},
|
},
|
||||||
migrations: {
|
migrations: {
|
||||||
stub: Schwifty.migrationsStubPath
|
stub: Schwifty.migrationsStubPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
production: {
|
production: {
|
||||||
migrateOnStart: false
|
migrateOnStart: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
plugin: {
|
plugin: {
|
||||||
$filter: { $env: 'NODE_ENV' },
|
$filter: { $env: 'NODE_ENV' },
|
||||||
$default: '@hapipal/hpal-debug',
|
$default: '@hapipal/hpal-debug',
|
||||||
production: Toys.noop
|
production: Toys.noop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Inert = require('@hapi/inert');
|
const Inert = require('@hapi/inert');
|
||||||
const Vision = require('@hapi/vision');
|
const Vision = require('@hapi/vision');
|
||||||
const HapiSwagger = require('hapi-swagger');
|
const HapiSwagger = require('hapi-swagger');
|
||||||
const Package = require('../../package.json');
|
const Package = require('../../package.json');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'app-swagger',
|
name: 'app-swagger',
|
||||||
async register(server) {
|
async register(server) {
|
||||||
|
|
||||||
await server.register([
|
await server.register([
|
||||||
Inert,
|
Inert,
|
||||||
Vision,
|
Vision,
|
||||||
{
|
{
|
||||||
plugin: HapiSwagger,
|
plugin: HapiSwagger,
|
||||||
options: {
|
options: {
|
||||||
info: {
|
info: {
|
||||||
version: Package.version
|
version: Package.version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Load modules
|
// Load modules
|
||||||
|
|
||||||
const Code = require('@hapi/code');
|
const Code = require('@hapi/code');
|
||||||
const Lab = require('@hapi/lab');
|
const Lab = require('@hapi/lab');
|
||||||
const Server = require('../server');
|
const Server = require('../server');
|
||||||
const Package = require('../package.json');
|
const Package = require('../package.json');
|
||||||
|
|
||||||
// Test shortcuts
|
// Test shortcuts
|
||||||
|
|
||||||
const { describe, it } = exports.lab = Lab.script();
|
const { describe, it } = exports.lab = Lab.script();
|
||||||
const { expect } = Code;
|
const { expect } = Code;
|
||||||
|
|
||||||
describe('Deployment', () => {
|
describe('Deployment', () => {
|
||||||
|
|
||||||
it('registers the main plugin.', async () => {
|
it('registers the main plugin.', async () => {
|
||||||
|
|
||||||
const server = await Server.deployment();
|
const server = await Server.deployment();
|
||||||
|
|
||||||
expect(server.registrations[Package.name]).to.exist();
|
expect(server.registrations[Package.name]).to.exist();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue