diff options
author | Marvin Borner | 2020-09-30 19:46:23 +0200 |
---|---|---|
committer | Marvin Borner | 2020-09-30 19:46:23 +0200 |
commit | a5e2f2db4ebaca6a21a81e00d7506772a7c0d59b (patch) | |
tree | 4c40f6b3ab27c4c03b4f061845db747016ee442a | |
parent | 4f6fe9fc1033e388c5cdf1dab6afa799547b30ef (diff) |
Quote server bootstrap
-rw-r--r-- | .prettierrc | 7 | ||||
-rw-r--r-- | quotes/.env.example | 4 | ||||
-rw-r--r-- | quotes/.eslintrc.js | 14 | ||||
-rw-r--r-- | quotes/.gitignore | 4 | ||||
-rw-r--r-- | quotes/index.js | 38 | ||||
-rw-r--r-- | quotes/package.json | 17 |
6 files changed, 84 insertions, 0 deletions
diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..c5f47ce --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "trailingComma": "es5", + "printWidth": 120, + "tabWidth": 4, + "semi": true, + "singleQuote": false +} diff --git a/quotes/.env.example b/quotes/.env.example new file mode 100644 index 0000000..89f11e4 --- /dev/null +++ b/quotes/.env.example @@ -0,0 +1,4 @@ +DB_HOST= +DB_USER= +DB_PWD= +DB_NAME= diff --git a/quotes/.eslintrc.js b/quotes/.eslintrc.js new file mode 100644 index 0000000..4d11b96 --- /dev/null +++ b/quotes/.eslintrc.js @@ -0,0 +1,14 @@ +module.exports = { + "env": { + "browser": true, + "commonjs": true, + "es2020": true, + "node": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 11 + }, + "rules": { + } +}; diff --git a/quotes/.gitignore b/quotes/.gitignore new file mode 100644 index 0000000..d17fe72 --- /dev/null +++ b/quotes/.gitignore @@ -0,0 +1,4 @@ +.env +*.db +*lock* +node_* diff --git a/quotes/index.js b/quotes/index.js new file mode 100644 index 0000000..e4d56e9 --- /dev/null +++ b/quotes/index.js @@ -0,0 +1,38 @@ +require("dotenv").config(); +const express = require("express"); +const mariadb = require("mariadb"); +const app = express(); +const pool = mariadb.createPool({ + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PWD, + database: process.env.DB_NAME, +}); + +let db_conn; + +pool.getConnection() + .then((conn) => { + db_conn = conn; + db_conn.release(); + }) + .catch((err) => { + console.error(err); + db_conn = null; + }); + +app.use(express.urlencoded({ extended: true })); +app.use(express.json()); + +app.use("/", express.static(__dirname + "/public")); + +app.get("/api/list", (req, res) => { + res.send("ok\n"); +}); + +app.on("close", () => { + console.log("CLOSE"); +}); + +console.log("Listening on port 5007"); +app.listen(5007); diff --git a/quotes/package.json b/quotes/package.json new file mode 100644 index 0000000..036eb45 --- /dev/null +++ b/quotes/package.json @@ -0,0 +1,17 @@ +{ + "name": "quotes", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT", + "dependencies": { + "dotenv": "^8.2.0", + "eslint": "^7.10.0", + "express": "^4.17.1", + "mariadb": "^2.4.2" + } +} |