diff --git a/config.json b/config.json index 09f32d4..6ff5727 100644 --- a/config.json +++ b/config.json @@ -1,8 +1,8 @@ { - "database": "blacksails", - "hostname": "0.0.0.0", + "database": "global", + "hostname": "localhost", "port": { - "https": "8443", - "http": "8080" + "https": "8080", + "http": "80" } } \ No newline at end of file diff --git a/package.json b/package.json index e7c31f9..004b2cc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mongodb-proxy", - "version": "23.01.14", - "description": "a REST api that works as a proxy for using MongoDB through HTTP endpoints with authentication included.", + "version": "23.5.2", + "description": "a REST api that works as a proxy for using MongoDB through HTTP REST-API endpoints with authentication included.", "main": "api/index.js", "scripts": { "setup": "npm install --save --include=dev", @@ -9,7 +9,9 @@ "dev": "nodemon ./src/index.ts", "build": "tsc -p ./tsconfig.json", "watch": "tsc -p ./tsconfig.json --watch", - "api": "nodemon ./api/index.js" + "api": "nodemon ./api/index.js", + "deploy": "vercel --prod || npx vercel --prod", + "preview": "vercel || npx vercel; echo \"You can find a preview build at https://mongodb-daveinchy.vercel.app ...\";" }, "dependencies": { "cors": "2.8.5", @@ -27,7 +29,9 @@ "dotenv": "16.0.2", "vercel": "^28.4.6" }, + "module": "true", "private": "true", - "author": "Dave Inchy ", - "license": "UNLICENSED" + "website": "https://doonline.nl", + "author": "Dave Inchy ", + "license": "MIT" } diff --git a/src/classes/server.class.ts b/src/classes/server.class.ts index 3047bdd..8c45eb4 100644 --- a/src/classes/server.class.ts +++ b/src/classes/server.class.ts @@ -29,12 +29,13 @@ export default class ProxyServer return this; } - loadRoutes(router: Array<[ string, Router ]>) { + loadRoutes(router: Array<[string, Router] | { endpoint: string, handler: Router }>) { const app: express.Express = this.getApp(); + // loading all routers router.forEach(( value ) => { - app.use(value[0], value[1]); + app.use(value[0] ? value[0] : value['endpoint'], value[1] ? value[1] : value['handler']); console.log(`[${this.package_config.name}]`, `added new router to the '${value[0]}' endpoint. \n`) }); @@ -47,8 +48,8 @@ export default class ProxyServer const app: express.Express = this.getApp(); // setup middleware - // app.use(cors()); - // app.use(express.json()); + app.use(cors()); + app.use(express.json()); app.use(MiddleWare.headers); app.use(MiddleWare.logger); @@ -63,7 +64,7 @@ export default class ProxyServer if (app !== null && app !== undefined) { this.setServer(false, http.createServer(app).listen(this.port['HTTP'])); - this.setServer(true, https.createServer(app).listen(this.port['HTTPS'])); + // this.setServer(true, https.createServer(app).listen(this.port['HTTPS'])); console.log(`[${this.package_config.name}]`, `listening with port ${this.port['HTTP']} \& port ${this.port['HTTPS']} \@ https://localhost:${this.port['HTTP']}/\n`); diff --git a/src/index.ts b/src/index.ts index 8057d1e..213a3b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,24 +1,18 @@ import Auth from "./routes/auth.route"; import Database from "./routes/crud.route"; +import Files from "./routes/files.route"; import Server from "./classes/server.class"; -import Website from "./routes/public.route"; import { Router } from "express"; -// classes - -// routes - -// setup const server: Server = new Server(); -const routes: Array<[string, Router]> = []; - -server.loadMiddleware(); +const routes: Array<[ string, Router ] | { endpoint: string, handler: Router }> = []; +routes.push(['/static/', Files]); routes.push(['/api/database', Database]); -// routes.push(['/api/static', Website]); routes.push(['/api/auth', Auth]); -server.loadRoutes(routes); +server.loadMiddleware(); +server.loadRoutes(routes); server.loadServer(); const app = server.getApp(); diff --git a/src/routes/public.route.ts b/src/routes/files.route.ts similarity index 79% rename from src/routes/public.route.ts rename to src/routes/files.route.ts index cf28333..79578fe 100644 --- a/src/routes/public.route.ts +++ b/src/routes/files.route.ts @@ -1,14 +1,14 @@ -import path from "path"; -import { Router } from "express"; - -const router: Router = Router(); - -router.use('/:file', (req, res) => { - const { params } = req; - res.status(200); - const path2 = __dirname + `../../../public/${params['file']}`; - res.setHeader('Content-Type', 'text/html; charset=UTF-8'); - res.sendFile(path.join(__dirname + path2)); -}); - +import path from "path"; +import { Router } from "express"; + +const router: Router = Router(); + +router.use('/:file', (req, res) => { + const { params } = req; + res.status(200); + const path2 = `../../../public/${params['file']}`; + res.setHeader('Content-Type', 'text/html; charset=UTF-8'); + res.sendFile(path.join(__dirname + path2)); +}); + export default router; \ No newline at end of file diff --git a/vercel.json b/vercel.json index a05142e..a9770a0 100644 --- a/vercel.json +++ b/vercel.json @@ -3,6 +3,10 @@ { "source": "/api/(.*)", "destination": "/api/" + }, + { + "source": "/static/(.*)", + "destination": "/api/" } ] } \ No newline at end of file