Version 0.1.0 - Ajout du serveur Express

This commit is contained in:
CICD - Pipeline 2023-10-21 18:16:11 +02:00
parent f3ecace914
commit 99f0392a6c
11 changed files with 1915 additions and 0 deletions

11
bin/global-variables.js Normal file
View File

@ -0,0 +1,11 @@
const path = require("path");
const root = path.resolve(__dirname, '../')
const __glob = {
ROUTES: root + path.sep + "routes" + path.sep
};
module.exports = { __glob };

90
bin/www Normal file
View File

@ -0,0 +1,90 @@
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../main');
var debug = require('debug')('neutral:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3001');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}

62
main.js Normal file
View File

@ -0,0 +1,62 @@
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const app = express();
const fs = require("fs");
const { __glob } = require('./bin/global-variables');
setup()
function getRouters() {
for(var route of fs.readdirSync(__glob.ROUTES)) {
if(route == "index.js") {
app.use("/", require(__glob.ROUTES + "index"))
} else {
app.use("/" + route.replace(".js", ""), require(__glob.ROUTES + route))
}
}
}
function setup() {
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
getRouters()
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
}
module.exports = app;

1482
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "neutral",
"version": "0.1.0",
"description": "Panel d'administration de Raphix",
"main": "index.js",
"scripts": {
"start": "nodemon ./bin/www"
},
"repository": {
"type": "git",
"url": "https://git.raphix.fr/infrastructure/neutral.git"
},
"nodemonConfig": {
"ext": "js, html",
"ignore": [
"*.json"
],
"delay": "10000000"
},
"keywords": [],
"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"ejs": "~2.6.1",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"loguix": "^1.2.0",
"nodemon": "^3.0.1"
},
"author": "Raphix",
"license": "ISC"
}

View File

@ -0,0 +1,88 @@
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
body {
padding: 2%;
background-color: #323031;
color: white;
font-size: 1vw;
font-family: 'Roboto', sans-serif !important;
}
/*Button*/
.btn {
background-color: transparent;
outline: none;
border-radius: 0.5vw;
border: 1px solid currentColor;
color: currentColor;
padding: 0.5vw;
transition: 0.2s;
}
.btn span {
transition: 0.2s;
}
.btn:hover {
box-shadow: 0px 0px 10px currentColor;
background-color: currentColor;
}
.btn:hover span {
color: black
}
.btn:active {
box-shadow: 0px 0px 10px currentColor;
background-color: transparent;
}
.btn:active span {
color: white
}
/* Miniaturiez Button */
.min {
width: 2vw !important;
height: 2vw !important;
border-radius: 100% !important;
font-size: 1vw !important;
display: flex;
justify-content: center;
align-items: center;
transition: 0.2s;
}
/*Colors*/
.red {
color: rgb(255, 63, 63) !important;
}
.blue {
color: rgb(66, 242, 255) !important;
}
.yellow {
color: rgb(255, 255, 27) !important;
}
.green {
color: rgb(64, 248, 64) !important;
}

9
routes/index.js Normal file
View File

@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index');
});
module.exports = router;

9
routes/stylepage.js Normal file
View File

@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('stylepage');
});
module.exports = router;

49
views/error.ejs Normal file
View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<title>Neutral - Erreur</title>
<link rel='stylesheet' href='/stylesheets/style.css'/>
<style>
body {
padding: 2%;
}
div {
background-color: rgb(32, 32, 32);
border-radius: 1vw;
padding: 2%;
}
button {
color: red;
background-color: transparent;
border-radius: 1vw;
border-color: red;
border-style: solid;
padding: 10px;
transition: all 0.2s ease 0s;
}
button:hover {
color: white;
background-color: red;
cursor: pointer;
}
</style>
</head>
<body>
<div>
<h1>Erreur</h1>
<h2><%= message %> - <%= error.status %></h1>
<pre><%= error.stack %></pre>
</div>
<br>
<a href="/"><button>Retourner sur le panel</button></a>
</body>
</html>

13
views/index.ejs Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Neutral</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1>Neutral - Home</h1>
<p>Welcome to Neutral</p>
<script defer="" src="https://use.fontawesome.com/releases/v6.4.2/js/all.js" crossorigin="anonymous"></script>
</body>
</html>

70
views/stylepage.ejs Normal file
View File

@ -0,0 +1,70 @@
<!DOCTYPE html>
<html>
<head>
<title>Neutral</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<h1>Neutral - Style Page</h1>
<p>Welcome to Neutral</p>
<p>Police : 'Roboto', sans-serif </p>
<style>
.box-color {
width: 5vw;
height: 5vw;
transition: 0.2s;
border: 1px solid;
}
.box-color:hover {
transform: scale(1.1);
}
.box-color:active {
transform: scale(1);
color: rgb(58, 255, 3);
}
button {
width: fit-content ;
}
.list-items {
display: flex;
flex-direction: column;
gap: 2vw;
}
</style>
<div class="list-items">
<button class="btn red"><span>Error Button</span></button>
<button class="btn blue "><span>Info Button</span></button>
<button class="btn yellow"><span>Warning Button</span></button>
<button class="btn green"><span>Confirm Button</span></button>
<button class="btn"><span>Default Button</span></button>
<button class="btn min red"><span><i class="fa fa-x"></i></span></button>
<button class="btn min blue"><span><i class="fa fa-info"></i></span></button>
<button class="btn min"><span><i class="fa fa-def"></i></span></button>
<div onclick="copyToClipboard('#323031')" style='background-color: #323031;' class="box-color"><p style="text-align: center;">#323031</p></div>
<div onclick="copyToClipboard('#3D3B3C')" style='background-color: #3D3B3C;' class="box-color"><p style="text-align: center;">#3D3B3C</p></div>
<div onclick="copyToClipboard('#7F7979')" style='background-color: #7F7979;' class="box-color"><p style="text-align: center;">#7F7979</p></div>
<div onclick="copyToClipboard('#C1BDB3')" style='background-color: #C1BDB3;' class="box-color"><p style="text-align: center;">#C1BDB3</p></div>
<div onclick="copyToClipboard('#5f5b6b')" style='background-color: #5f5b6b;' class="box-color"><p style="text-align: center;">#5F5B6B</p></div>
</div>
<script>
function copyToClipboard(text) {
navigator.clipboard.writeText(text)
}
</script>
<script defer="" src="https://use.fontawesome.com/releases/v6.4.2/js/all.js" crossorigin="anonymous"></script>
</body>
</html>