initial commit

master
Cemal Odabasioglu 2024-01-25 16:36:58 +01:00
commit e131da0931
12 changed files with 170 additions and 0 deletions

8
.eslintrc.json Normal file
View File

@ -0,0 +1,8 @@
{
"extends": "@hapi/eslint-config-hapi",
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "script"
}
}

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
server/.env

2
.npmignore Normal file
View File

@ -0,0 +1,2 @@
*
!lib/**

1
README.md Normal file
View File

@ -0,0 +1 @@
# iut-project-cemal

0
lib/.hc.js Normal file
View File

14
lib/index.js Normal file
View File

@ -0,0 +1,14 @@
'use strict';
const HauteCouture = require('@hapipal/haute-couture');
const Package = require('../package.json');
exports.plugin = {
pkg: Package,
register: async (server, options) => {
// Custom plugin code can go here
await HauteCouture.compose(server, options);
}
};

0
lib/routes/.gitkeep Normal file
View File

38
package.json Normal file
View File

@ -0,0 +1,38 @@
{
"name": "iut-project-cemal",
"version": "1.0.0",
"description": "",
"author": "",
"license": "ISC",
"main": "lib/index.js",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"start": "node server",
"test": "lab -a @hapi/code -L",
"lint": "eslint ."
},
"dependencies": {
"@hapi/boom": "9.x.x",
"@hapipal/haute-couture": "4.x.x",
"joi": "17.x.x"
},
"devDependencies": {
"@hapi/code": "8.x.x",
"@hapi/eslint-config-hapi": "13.x.x",
"@hapi/eslint-plugin-hapi": "4.x.x",
"@hapi/glue": "8.x.x",
"@hapi/hapi": "20.x.x",
"@hapi/lab": "24.x.x",
"@hapipal/confidence": "6.x.x",
"@hapipal/hpal": "3.x.x",
"@hapipal/hpal-debug": "2.x.x",
"@hapipal/toys": "3.x.x",
"babel-eslint": "10.x.x",
"dotenv": "8.x.x",
"eslint": "7.x.x",
"exiting": "6.x.x"
}
}

6
server/.env-keep Normal file
View File

@ -0,0 +1,6 @@
# Rename me to .env then fill me with runtime configuration and credentials
# Just don't try to check me into your repo :)
# Confused? See https://github.com/motdotla/dotenv
#
# e.g.
# PORT=4000

31
server/index.js Normal file
View File

@ -0,0 +1,31 @@
'use strict';
const Glue = require('@hapi/glue');
const Exiting = require('exiting');
const Manifest = require('./manifest');
exports.deployment = async ({ start } = {}) => {
const manifest = Manifest.get('/', process.env);
const server = await Glue.compose(manifest, { relativeTo: __dirname });
if (start) {
await Exiting.createManager(server).start();
server.log(['start'], `Server started at ${server.info.uri}`);
return server;
}
await server.initialize();
return server;
};
if (require.main === module) {
exports.deployment({ start: true });
process.on('unhandledRejection', (err) => {
throw err;
});
}

45
server/manifest.js Normal file
View File

@ -0,0 +1,45 @@
'use strict';
const Dotenv = require('dotenv');
const Confidence = require('@hapipal/confidence');
const Toys = require('@hapipal/toys');
// Pull .env into process.env
Dotenv.config({ path: `${__dirname}/.env` });
// Glue manifest as a confidence store
module.exports = new Confidence.Store({
server: {
host: 'localhost',
port: {
$param: 'PORT',
$coerce: 'number',
$default: 3000
},
debug: {
$filter: 'NODE_ENV',
$default: {
log: ['error', 'start'],
request: ['error']
},
production: {
request: ['implementation']
}
}
},
register: {
plugins: [
{
plugin: '../lib', // Main plugin
options: {}
},
{
plugin: {
$filter: 'NODE_ENV',
$default: '@hapipal/hpal-debug',
production: Toys.noop
}
}
]
}
});

23
test/index.js Normal file
View File

@ -0,0 +1,23 @@
'use strict';
// Load modules
const Code = require('@hapi/code');
const Lab = require('@hapi/lab');
const Server = require('../server');
const Package = require('../package.json');
// Test shortcuts
const { describe, it } = exports.lab = Lab.script();
const { expect } = Code;
describe('Deployment', () => {
it('registers the main plugin.', async () => {
const server = await Server.deployment();
expect(server.registrations[Package.name]).to.exist();
});
});