Skip to content

Commit

Permalink
Final Release: v23.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveInchy committed May 2, 2023
1 parent 87d58fd commit ec298f8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
8 changes: 4 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"database": "blacksails",
"hostname": "0.0.0.0",
"database": "global",
"hostname": "localhost",
"port": {
"https": "8443",
"http": "8080"
"https": "8080",
"http": "80"
}
}
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"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",
"start": "node ./api/index.js",
"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",
Expand All @@ -27,7 +29,9 @@
"dotenv": "16.0.2",
"vercel": "^28.4.6"
},
"module": "true",
"private": "true",
"author": "Dave Inchy <[email protected]>",
"license": "UNLICENSED"
"website": "https://doonline.nl",
"author": "Dave Inchy <github.com/daveinchy>",
"license": "MIT"
}
11 changes: 6 additions & 5 deletions src/classes/server.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
});

Expand All @@ -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);

Expand All @@ -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`);

Expand Down
16 changes: 5 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
26 changes: 13 additions & 13 deletions src/routes/public.route.ts → src/routes/files.route.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
{
"source": "/api/(.*)",
"destination": "/api/"
},
{
"source": "/static/(.*)",
"destination": "/api/"
}
]
}

0 comments on commit ec298f8

Please sign in to comment.