22
									
								
								src/app.ts
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/app.ts
									
									
									
									
									
								
							| @@ -7,21 +7,17 @@ import bodyparser from "body-parser"; | ||||
| import 'reflect-metadata'; | ||||
| import routerMain from './routes/index'; | ||||
| // const loaders = require('./loaders'); | ||||
| import * as loaders from './loaders/index'; | ||||
| import loaders from './loaders/index'; | ||||
|  | ||||
| dotenvSafe.config(); | ||||
| const app = express(); | ||||
| let app = express(); | ||||
| const PORT = process.env.APP_PORT || 4010; | ||||
|  | ||||
| createConnection() | ||||
| 	.then((connection) => {}) | ||||
| 	.catch((err) => { | ||||
| 		consola.error(err); | ||||
| 	}) | ||||
| 	.finally(() => { | ||||
| 		// await loaders.init(app); | ||||
| 		app.use('/api/', routerMain); | ||||
| 		app.listen(PORT, () => { | ||||
| 			consola.success(`⚡️[server]: Server is running at http://localhost:${PORT}`); | ||||
| 		}); | ||||
| async function main() { | ||||
| 	await loaders(app); | ||||
| 	app.listen(PORT, () => { | ||||
| 		consola.success(`⚡️[server]: Server is running at http://localhost:${PORT}`); | ||||
| 	}); | ||||
| } | ||||
|  | ||||
| main() | ||||
							
								
								
									
										5
									
								
								src/loaders/database.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/loaders/database.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| import {createConnection} from "typeorm"; | ||||
|  | ||||
| export default async ()=> { | ||||
| 	return await createConnection(); | ||||
| }; | ||||
							
								
								
									
										14
									
								
								src/loaders/express.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/loaders/express.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| import {Application} from "express"; | ||||
| import bodyParser from 'body-parser'; | ||||
| import cors from 'cors'; | ||||
|  | ||||
| export default async (app: Application) => { | ||||
| 	app.get('/status', (req, res) => res.status(200).end()); | ||||
| 	app.enable('trust proxy'); | ||||
|  | ||||
| 	app.use(cors()); | ||||
| 	// app.use(bodyParser.urlencoded({ extended: false })); | ||||
|  | ||||
| 	// more middlewares | ||||
| 	return app; | ||||
| }; | ||||
| @@ -1,14 +1,11 @@ | ||||
| import express from 'express'; | ||||
| import bodyParser from 'body-parser'; | ||||
| import cors from 'cors'; | ||||
| import expressLoader from "./express"; | ||||
| import routeLoader from "./routes"; | ||||
| import databaseLoader from "./database"; | ||||
| import {Application} from "express"; | ||||
|  | ||||
| export default async (app) => { | ||||
| 	app.get('/status', (req, res) => res.status(200).end()); | ||||
| 	app.enable('trust proxy'); | ||||
|  | ||||
| 	app.use(cors()); | ||||
| 	// app.use(bodyParser.urlencoded({ extended: false })); | ||||
|  | ||||
| 	// more middlewares | ||||
| 	return app; | ||||
| export default async (app: Application) => { | ||||
|     await expressLoader(app); | ||||
|     await routeLoader(app); | ||||
|     databaseLoader(); | ||||
|     return app; | ||||
| }; | ||||
|   | ||||
							
								
								
									
										7
									
								
								src/loaders/routes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/loaders/routes.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| import {Application} from "express"; | ||||
| import routerMain from "../routes/index"; | ||||
|  | ||||
| export default async (app: Application) => { | ||||
| 	app.use('/api/', routerMain); | ||||
| 	return app; | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user