commit e131da0931c225e86886b88fd90e85a497382306 Author: cemal Date: Thu Jan 25 16:36:58 2024 +0100 initial commit diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..94dadcd --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,8 @@ +{ + "extends": "@hapi/eslint-config-hapi", + "parser": "babel-eslint", + "parserOptions": { + "ecmaVersion": 2020, + "sourceType": "script" + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44b01e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +server/.env diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..93f3929 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +* +!lib/** diff --git a/README.md b/README.md new file mode 100644 index 0000000..17ea155 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# iut-project-cemal diff --git a/lib/.hc.js b/lib/.hc.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..0a6a010 --- /dev/null +++ b/lib/index.js @@ -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); + } +}; diff --git a/lib/routes/.gitkeep b/lib/routes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json new file mode 100644 index 0000000..3d39189 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/server/.env-keep b/server/.env-keep new file mode 100644 index 0000000..8426104 --- /dev/null +++ b/server/.env-keep @@ -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 diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..4c997c6 --- /dev/null +++ b/server/index.js @@ -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; + }); +} diff --git a/server/manifest.js b/server/manifest.js new file mode 100644 index 0000000..ffb9f26 --- /dev/null +++ b/server/manifest.js @@ -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 + } + } + ] + } +}); diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..917ef22 --- /dev/null +++ b/test/index.js @@ -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(); + }); +});