pull/12/head
Damien Broqua 10 months ago
parent 6debd00e77
commit e495e11198
  1. 3
      .eslintignore
  2. 22
      .eslintrc.js
  3. 2
      .gitignore
  4. 4
      .husky/pre-commit
  5. 61
      package.json
  6. 14
      src/app.js
  7. 57
      src/bin/www.js
  8. 4
      src/config/index.js
  9. 11
      src/routes/index.js

@ -0,0 +1,3 @@
dist/**
node_modules/**
test-reports/**

@ -0,0 +1,22 @@
module.exports = {
'env': {
'es6': true,
'node': true,
},
'extends': [
'google',
],
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly',
},
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module',
},
'rules': {
'max-len': ['error', {'code': 180}],
'new-cap': ['error', {'capIsNewExceptions': ['ENUM', 'ARRAY', 'TEXT', 'STRING', 'ObjectId']}],
},
};

2
.gitignore vendored

@ -118,3 +118,5 @@ dist
.yarn/install-state.gz
.pnp.*
dist
yarn.lock

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged

@ -0,0 +1,61 @@
{
"name": "nodecdtheque",
"version": "1.0.0",
"description": "Simple application to manage your CD/Vinyl collection",
"scripts": {
"start": "node ./dist/bin/www",
"dev": "npm-run-all build start",
"watch": "nodemon",
"prebuild": "rimraf dist",
"build": "babel ./src --out-dir dist",
"test": "jest",
"prepare": "husky install"
},
"repository": {
"type": "git",
"url": "git@git.darkou.fr:dbroqua/nodecdtheque.git"
},
"author": {
"name": "Damien Broqua",
"email": "contact@darkou.fr",
"url": "https://www.darkou.fr"
},
"license": "GPL-3.0-or-later",
"devDependencies": {
"@babel/cli": "^7.17.0",
"@babel/core": "^7.17.2",
"@babel/preset-env": "^7.16.11",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.3",
"nodemon": "^2.0.15",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2"
},
"dependencies": {
"express": "^4.17.2"
},
"nodemonConfig": {
"exec": "npm run dev",
"watch": [
"src/*"
],
"ignore": [
"**/__tests__/**",
"*.test.js",
"*.spec.js"
]
},
"babel": {
"presets": [
"@babel/preset-env"
]
},
"jest": {
"testEnvironment": "node"
},
"lint-staged": {
"src/**/*.js": "eslint --cache --fix"
}
}

@ -0,0 +1,14 @@
import express from 'express';
import path from 'path';
import indexRouter from './routes/index';
const app = express();
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, '../public')));
app.use('/', indexRouter);
export default app;

@ -0,0 +1,57 @@
#!/usr/bin/env node
/**
* Module dependencies.
*/
import app from '../app';
import debugLib from 'debug';
import http from 'http';
import {port} from '../config';
const debug = debugLib('nodecdtheque:server');
const server = http.createServer(app);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Event listener for HTTP server "error" event.
* @param {*} error
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
const 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() {
const addr = server.address();
const bind = typeof addr === 'string' ?
'pipe ' + addr :
'port ' + addr.port;
debug('Listening on ' + bind);
}

@ -0,0 +1,4 @@
module.exports = {
nodeEnv: process.env.NODE_ENV || 'development',
port: parseInt(process.env.PORT || '3001', 10),
};

@ -0,0 +1,11 @@
import express from 'express';
// eslint-disable-next-line new-cap
const router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', {title: 'World'});
});
export default router;
Loading…
Cancel
Save