forked from fr/deguapp
		
	Clean setup - nork v4, nothing else
This commit is contained in:
		
							
								
								
									
										3
									
								
								api/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								api/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					node_modules/
 | 
				
			||||||
 | 
					package-lock.json
 | 
				
			||||||
 | 
					.env
 | 
				
			||||||
							
								
								
									
										1
									
								
								api/norkconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								api/norkconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					{ "lang": "ts" }
 | 
				
			||||||
							
								
								
									
										61
									
								
								api/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								api/package.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "deguapp-api",
 | 
				
			||||||
 | 
						"version": "2.0.0",
 | 
				
			||||||
 | 
						"description": "DeguApp REST API",
 | 
				
			||||||
 | 
						"main": "dist/app.js",
 | 
				
			||||||
 | 
						"bin": "dist/app.js",
 | 
				
			||||||
 | 
						"types": "dist/app.d.ts",
 | 
				
			||||||
 | 
						"scripts": {
 | 
				
			||||||
 | 
							"start": "npm run start:prod",
 | 
				
			||||||
 | 
							"start:dev": "tsx watch src/server.ts",
 | 
				
			||||||
 | 
							"start:prod": "node dist/server.js",
 | 
				
			||||||
 | 
							"tsc": "tsc -p .",
 | 
				
			||||||
 | 
							"clean": "rimraf dist",
 | 
				
			||||||
 | 
							"copy-assets": "ts-node src/utils/copyAssets",
 | 
				
			||||||
 | 
							"build": "npm-run-all clean tsc copy-assets",
 | 
				
			||||||
 | 
							"test": "mocha --config .mocharc.json --watch src/**/*.test.ts",
 | 
				
			||||||
 | 
							"format": "npx prettier --write ."
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"author": "Filip Rojek",
 | 
				
			||||||
 | 
						"license": "MIT",
 | 
				
			||||||
 | 
						"dependencies": {
 | 
				
			||||||
 | 
							"colors": "1.4.0",
 | 
				
			||||||
 | 
							"dotenv": "^16.4.5",
 | 
				
			||||||
 | 
							"express": "^4.19.2",
 | 
				
			||||||
 | 
							"fs-extra": "^10.0.0",
 | 
				
			||||||
 | 
							"inquirer": "^8.1.2",
 | 
				
			||||||
 | 
							"morgan": "^1.10.0",
 | 
				
			||||||
 | 
							"pad": "^3.2.0",
 | 
				
			||||||
 | 
							"path": "^0.12.7"
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"devDependencies": {
 | 
				
			||||||
 | 
							"@types/chai": "^4.2.22",
 | 
				
			||||||
 | 
							"@types/express": "^4.17.21",
 | 
				
			||||||
 | 
							"@types/fs-extra": "^9.0.13",
 | 
				
			||||||
 | 
							"@types/inquirer": "^8.1.3",
 | 
				
			||||||
 | 
							"@types/mocha": "^9.0.0",
 | 
				
			||||||
 | 
							"@types/morgan": "^1.9.9",
 | 
				
			||||||
 | 
							"@types/shelljs": "^0.8.11",
 | 
				
			||||||
 | 
							"@typescript-eslint/eslint-plugin": "^5.5.0",
 | 
				
			||||||
 | 
							"@typescript-eslint/parser": "^5.5.0",
 | 
				
			||||||
 | 
							"chai": "^4.3.4",
 | 
				
			||||||
 | 
							"eslint": "^8.3.0",
 | 
				
			||||||
 | 
							"http": "^0.0.1-security",
 | 
				
			||||||
 | 
							"mocha": "^9.1.3",
 | 
				
			||||||
 | 
							"npm-run-all": "^4.1.5",
 | 
				
			||||||
 | 
							"prettier": "^2.7.1",
 | 
				
			||||||
 | 
							"rimraf": "^3.0.2",
 | 
				
			||||||
 | 
							"shelljs": "^0.8.5",
 | 
				
			||||||
 | 
							"ts-node": "^10.9.2",
 | 
				
			||||||
 | 
							"tsx": "^4.7.3",
 | 
				
			||||||
 | 
							"typescript": "^4.5.2"
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"repository": {
 | 
				
			||||||
 | 
							"type": "git",
 | 
				
			||||||
 | 
							"url": "git+https://github.com/filiprojek/nork.git"
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"bugs": {
 | 
				
			||||||
 | 
							"url": "https://github.com/filiprojek/nork/issues"
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"homepage": "https://github.com/filiprojek/nork/blob/master/README.md"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										42
									
								
								api/src/app.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								api/src/app.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					import express from "express";
 | 
				
			||||||
 | 
					import morgan from "morgan";
 | 
				
			||||||
 | 
					//import path from 'path'
 | 
				
			||||||
 | 
					//import cors from 'cors'
 | 
				
			||||||
 | 
					//import cookieParser from 'cookie-parser'
 | 
				
			||||||
 | 
					import { router as routes } from "./routes";
 | 
				
			||||||
 | 
					//import { router as middlewares } from './middlewares'
 | 
				
			||||||
 | 
					//import env from './config/environment'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//export let corsWhitelist: Array<string>
 | 
				
			||||||
 | 
					//if (env.CORS_WHITELIST != 'undefined') {
 | 
				
			||||||
 | 
					//	corsWhitelist = [...['http://localhost:8080', 'http://localhost:6040'], ...env.CORS_WHITELIST.split(';')]
 | 
				
			||||||
 | 
					//} else {
 | 
				
			||||||
 | 
					//	corsWhitelist = ['http://localhost:8080', 'http://localhost:6040']
 | 
				
			||||||
 | 
					//}
 | 
				
			||||||
 | 
					//const corsOptions = {
 | 
				
			||||||
 | 
					//	origin: function (origin: any, callback: any) {
 | 
				
			||||||
 | 
					//		if (!origin || corsWhitelist.indexOf(origin) !== -1) {
 | 
				
			||||||
 | 
					//			callback(null, true)
 | 
				
			||||||
 | 
					//		} else {
 | 
				
			||||||
 | 
					//			callback(new Error('Not allowed by CORS'))
 | 
				
			||||||
 | 
					//		}
 | 
				
			||||||
 | 
					//	},
 | 
				
			||||||
 | 
					//	optionsSuccessStatus: 200,
 | 
				
			||||||
 | 
					//	credentials: true
 | 
				
			||||||
 | 
					//}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const app = express();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Middlewares
 | 
				
			||||||
 | 
					//app.use(middlewares)
 | 
				
			||||||
 | 
					//app.set('view engine', 'ejs')
 | 
				
			||||||
 | 
					//app.set('views', path.join(__dirname, 'views'))
 | 
				
			||||||
 | 
					//app.use(cors(corsOptions))
 | 
				
			||||||
 | 
					app.use(morgan("dev"));
 | 
				
			||||||
 | 
					app.use(express.urlencoded({ extended: true }));
 | 
				
			||||||
 | 
					app.use(express.json());
 | 
				
			||||||
 | 
					//app.use(express.static(path.join(__dirname, 'public')))
 | 
				
			||||||
 | 
					//app.use(cookieParser())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Routes
 | 
				
			||||||
 | 
					app.use(routes);
 | 
				
			||||||
							
								
								
									
										4
									
								
								api/src/config/environment.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								api/src/config/environment.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					import path from "path";
 | 
				
			||||||
 | 
					import { Env } from "nork";
 | 
				
			||||||
 | 
					const env = Env.get(path.join(__dirname, "../.env"));
 | 
				
			||||||
 | 
					export default env;
 | 
				
			||||||
							
								
								
									
										15
									
								
								api/src/routes/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								api/src/routes/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					import { Request, Response, Router } from "express";
 | 
				
			||||||
 | 
					import path from "path";
 | 
				
			||||||
 | 
					//import authRoutes from "./authRoutes";
 | 
				
			||||||
 | 
					export const router = Router();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//router.use("/api/auth", authRoutes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//router.get("*", (req: Request, res: Response) => {
 | 
				
			||||||
 | 
					//  res.sendFile(path.join(__dirname, "../views/index.html"));
 | 
				
			||||||
 | 
					//});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 404
 | 
				
			||||||
 | 
					router.use((req: Request, res: Response) => {
 | 
				
			||||||
 | 
					  res.status(404).send("Error 404\n");
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										26
									
								
								api/src/server.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								api/src/server.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					import http from "http";
 | 
				
			||||||
 | 
					import { app } from "./app";
 | 
				
			||||||
 | 
					import env from "./config/environment";
 | 
				
			||||||
 | 
					//const env = {
 | 
				
			||||||
 | 
					//  APP_PORT: 8080,
 | 
				
			||||||
 | 
					//  APP_HOSTNAME: "127.0.0.1",
 | 
				
			||||||
 | 
					//};
 | 
				
			||||||
 | 
					import { Log } from "nork";
 | 
				
			||||||
 | 
					//import database from './config/database'
 | 
				
			||||||
 | 
					const port: number = env.APP_PORT || 8080;
 | 
				
			||||||
 | 
					const hostname: string = env.APP_HOSTNAME || "localhost";
 | 
				
			||||||
 | 
					export const server = http.createServer(app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Server
 | 
				
			||||||
 | 
					export function runServer(): void {
 | 
				
			||||||
 | 
					  server.listen(port, hostname, () => {
 | 
				
			||||||
 | 
					    Log.info(200, `Server is listening on http://${hostname}:${port}`);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//if (!env.NORK.database) {
 | 
				
			||||||
 | 
					runServer();
 | 
				
			||||||
 | 
					//} else {
 | 
				
			||||||
 | 
					//	const db_connection = database()
 | 
				
			||||||
 | 
					//	runServer()
 | 
				
			||||||
 | 
					//}
 | 
				
			||||||
							
								
								
									
										15
									
								
								api/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								api/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
						"compilerOptions": {
 | 
				
			||||||
 | 
							"target": "es6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
 | 
				
			||||||
 | 
							"module": "commonjs" /* Specify what module code is generated. */,
 | 
				
			||||||
 | 
							"outDir": "./dist" /* Specify an output folder for all emitted files. */,
 | 
				
			||||||
 | 
							"rootDir": "./src" /* Specify the root folder within your source files. */,
 | 
				
			||||||
 | 
							"strict": true /* Enable all strict type-checking options. */,
 | 
				
			||||||
 | 
							"baseUrl": "./" /* Base directory to resolve non-absolute module names. */,
 | 
				
			||||||
 | 
							"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
 | 
				
			||||||
 | 
							"skipLibCheck": true /* Skip type checking all .d.ts files. */,
 | 
				
			||||||
 | 
							"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
 | 
				
			||||||
 | 
							"declaration": true
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"exclude": ["_old", "node_modules", "src/make-files", "src/skeletons", "src/tests", "src/interfaces", "src/utils"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user