middleware
This commit is contained in:
		
							parent
							
								
									0c0465623c
								
							
						
					
					
						commit
						e9079d3489
					
				|  | @ -9,12 +9,15 @@ | ||||||
|       "version": "1.0.0", |       "version": "1.0.0", | ||||||
|       "license": "GPL-3.0-or-later", |       "license": "GPL-3.0-or-later", | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|  |         "body-parser": "^1.20.2", | ||||||
|         "chai": "^4.3.8", |         "chai": "^4.3.8", | ||||||
|         "chai-http": "^4.4.0", |         "chai-http": "^4.4.0", | ||||||
|  |         "cors": "^2.8.5", | ||||||
|         "express": "^4.18.2", |         "express": "^4.18.2", | ||||||
|         "knex": "^2.5.1", |         "knex": "^2.5.1", | ||||||
|         "mocha": "^10.2.0", |         "mocha": "^10.2.0", | ||||||
|         "pino": "^8.15.0", |         "pino": "^8.15.0", | ||||||
|  |         "pino-http": "^8.5.0", | ||||||
|         "sqlite3": "^5.1.6" |         "sqlite3": "^5.1.6" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  | @ -326,12 +329,12 @@ | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/body-parser": { |     "node_modules/body-parser": { | ||||||
|       "version": "1.20.1", |       "version": "1.20.2", | ||||||
|       "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", |       "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", | ||||||
|       "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", |       "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|         "bytes": "3.1.2", |         "bytes": "3.1.2", | ||||||
|         "content-type": "~1.0.4", |         "content-type": "~1.0.5", | ||||||
|         "debug": "2.6.9", |         "debug": "2.6.9", | ||||||
|         "depd": "2.0.0", |         "depd": "2.0.0", | ||||||
|         "destroy": "1.2.0", |         "destroy": "1.2.0", | ||||||
|  | @ -339,7 +342,7 @@ | ||||||
|         "iconv-lite": "0.4.24", |         "iconv-lite": "0.4.24", | ||||||
|         "on-finished": "2.4.1", |         "on-finished": "2.4.1", | ||||||
|         "qs": "6.11.0", |         "qs": "6.11.0", | ||||||
|         "raw-body": "2.5.1", |         "raw-body": "2.5.2", | ||||||
|         "type-is": "~1.6.18", |         "type-is": "~1.6.18", | ||||||
|         "unpipe": "1.0.0" |         "unpipe": "1.0.0" | ||||||
|       }, |       }, | ||||||
|  | @ -699,6 +702,18 @@ | ||||||
|       "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", |       "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", | ||||||
|       "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==" |       "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==" | ||||||
|     }, |     }, | ||||||
|  |     "node_modules/cors": { | ||||||
|  |       "version": "2.8.5", | ||||||
|  |       "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", | ||||||
|  |       "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", | ||||||
|  |       "dependencies": { | ||||||
|  |         "object-assign": "^4", | ||||||
|  |         "vary": "^1" | ||||||
|  |       }, | ||||||
|  |       "engines": { | ||||||
|  |         "node": ">= 0.10" | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     "node_modules/debug": { |     "node_modules/debug": { | ||||||
|       "version": "2.6.9", |       "version": "2.6.9", | ||||||
|       "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", |       "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", | ||||||
|  | @ -935,6 +950,43 @@ | ||||||
|         "node": ">= 0.10.0" |         "node": ">= 0.10.0" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  |     "node_modules/express/node_modules/body-parser": { | ||||||
|  |       "version": "1.20.1", | ||||||
|  |       "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", | ||||||
|  |       "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", | ||||||
|  |       "dependencies": { | ||||||
|  |         "bytes": "3.1.2", | ||||||
|  |         "content-type": "~1.0.4", | ||||||
|  |         "debug": "2.6.9", | ||||||
|  |         "depd": "2.0.0", | ||||||
|  |         "destroy": "1.2.0", | ||||||
|  |         "http-errors": "2.0.0", | ||||||
|  |         "iconv-lite": "0.4.24", | ||||||
|  |         "on-finished": "2.4.1", | ||||||
|  |         "qs": "6.11.0", | ||||||
|  |         "raw-body": "2.5.1", | ||||||
|  |         "type-is": "~1.6.18", | ||||||
|  |         "unpipe": "1.0.0" | ||||||
|  |       }, | ||||||
|  |       "engines": { | ||||||
|  |         "node": ">= 0.8", | ||||||
|  |         "npm": "1.2.8000 || >= 1.4.16" | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     "node_modules/express/node_modules/raw-body": { | ||||||
|  |       "version": "2.5.1", | ||||||
|  |       "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", | ||||||
|  |       "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", | ||||||
|  |       "dependencies": { | ||||||
|  |         "bytes": "3.1.2", | ||||||
|  |         "http-errors": "2.0.0", | ||||||
|  |         "iconv-lite": "0.4.24", | ||||||
|  |         "unpipe": "1.0.0" | ||||||
|  |       }, | ||||||
|  |       "engines": { | ||||||
|  |         "node": ">= 0.8" | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     "node_modules/fast-redact": { |     "node_modules/fast-redact": { | ||||||
|       "version": "3.3.0", |       "version": "3.3.0", | ||||||
|       "resolved": "https://registry.npmjs.org/fast-redact/-/fast-redact-3.3.0.tgz", |       "resolved": "https://registry.npmjs.org/fast-redact/-/fast-redact-3.3.0.tgz", | ||||||
|  | @ -2300,6 +2352,17 @@ | ||||||
|         "split2": "^4.0.0" |         "split2": "^4.0.0" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|  |     "node_modules/pino-http": { | ||||||
|  |       "version": "8.5.0", | ||||||
|  |       "resolved": "https://registry.npmjs.org/pino-http/-/pino-http-8.5.0.tgz", | ||||||
|  |       "integrity": "sha512-kLGKNLyfWfdmrG1Ug0YdYpCTGbNcuD/YGC3g+elRU/Cm44UTs+tj/dZTxDN3bYauekxFxdLZhJuZdKKl0cml9w==", | ||||||
|  |       "dependencies": { | ||||||
|  |         "get-caller-file": "^2.0.5", | ||||||
|  |         "pino": "^8.0.0", | ||||||
|  |         "pino-std-serializers": "^6.0.0", | ||||||
|  |         "process-warning": "^2.0.0" | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     "node_modules/pino-std-serializers": { |     "node_modules/pino-std-serializers": { | ||||||
|       "version": "6.2.2", |       "version": "6.2.2", | ||||||
|       "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.2.2.tgz", |       "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.2.2.tgz", | ||||||
|  | @ -2385,9 +2448,9 @@ | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/raw-body": { |     "node_modules/raw-body": { | ||||||
|       "version": "2.5.1", |       "version": "2.5.2", | ||||||
|       "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", |       "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", | ||||||
|       "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", |       "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|         "bytes": "3.1.2", |         "bytes": "3.1.2", | ||||||
|         "http-errors": "2.0.0", |         "http-errors": "2.0.0", | ||||||
|  |  | ||||||
|  | @ -9,12 +9,15 @@ | ||||||
|   "author": "Andrzej Stepien", |   "author": "Andrzej Stepien", | ||||||
|   "license": "GPL-3.0-or-later", |   "license": "GPL-3.0-or-later", | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|  |     "body-parser": "^1.20.2", | ||||||
|     "chai": "^4.3.8", |     "chai": "^4.3.8", | ||||||
|     "chai-http": "^4.4.0", |     "chai-http": "^4.4.0", | ||||||
|  |     "cors": "^2.8.5", | ||||||
|     "express": "^4.18.2", |     "express": "^4.18.2", | ||||||
|     "knex": "^2.5.1", |     "knex": "^2.5.1", | ||||||
|     "mocha": "^10.2.0", |     "mocha": "^10.2.0", | ||||||
|     "pino": "^8.15.0", |     "pino": "^8.15.0", | ||||||
|  |     "pino-http": "^8.5.0", | ||||||
|     "sqlite3": "^5.1.6" |     "sqlite3": "^5.1.6" | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										25
									
								
								server.mjs
								
								
								
								
							
							
						
						
									
										25
									
								
								server.mjs
								
								
								
								
							|  | @ -1,20 +1,27 @@ | ||||||
| import  express from "express"; | import express from "express" | ||||||
|  | import pinoHTTP from 'pino-http' | ||||||
|  | import logger from "./logger.mjs"; | ||||||
|  | import bodyParser from "body-parser"; | ||||||
|  | import { Data } from "./objects/Data.mjs"; | ||||||
|  | import { db } from "./db.mjs"; | ||||||
|  | import { getEndpoints } from "./objects/Endpoints.mjs"; | ||||||
|  | import cors from 'cors' | ||||||
| 
 | 
 | ||||||
| const app = express() | const app = express() | ||||||
| const port = 4000 | const port = 4000 | ||||||
| app.use( | const corsOptions={ | ||||||
|   pinoHTTP({ |  | ||||||
|     logger, |  | ||||||
|   }), |  | ||||||
|   cors({ |  | ||||||
|   origin: ['http://localhost:5173'] |   origin: ['http://localhost:5173'] | ||||||
|   }), | } | ||||||
|   bodyParser.json() | app.use(cors()) | ||||||
| ) | app.use(pinoHTTP({logger})) | ||||||
|  | app.use(bodyParser.json()) | ||||||
|  |    | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| const data = new Data(db) | const data = new Data(db) | ||||||
| await data.init() | await data.init() | ||||||
|  | 
 | ||||||
| app.use('/api',getEndpoints(data)) | app.use('/api',getEndpoints(data)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue