Skip to content

Commit 2c44d5b

Browse files
committed
First commit
0 parents  commit 2c44d5b

File tree

9 files changed

+683
-0
lines changed

9 files changed

+683
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
dist/
4+
5+
node_modules/

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
# Socket-Server
4+
5+
6+
Reconstruir módulos de Node
7+
```
8+
npm install
9+
```
10+
11+
Generar el DIST
12+
```
13+
tsc -w
14+
```
15+
16+
Levantar servidor, cualquiera de estos dos comandos
17+
```
18+
nodemon dist/
19+
node dist/
20+
```
21+
22+
23+

classes/server.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
import express from 'express';
3+
import { SERVER_PORT } from '../global/environment';
4+
5+
6+
// Clase usada para subir un servidor express
7+
// default - indica que es el paquete por defecto a exportar para que otros lo importen
8+
export default class Server {
9+
10+
public app: express.Application;
11+
public port: number;
12+
13+
14+
constructor() {
15+
16+
this.app = express();
17+
this.port = SERVER_PORT;
18+
19+
}
20+
21+
start( callback: Function ) {
22+
23+
this.app.listen( this.port, callback );
24+
25+
}
26+
27+
}

global/environment.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
// En servidores como Heroku, ya nos provee de process.env
3+
// Number(string) hace cast de string a number
4+
export const SERVER_PORT: number = Number( process.env.PORT ) || 5000;

index.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Server from './classes/server';
2+
import router from './routes/router';
3+
import bodyParser from 'body-parser';
4+
import cors from 'cors';
5+
6+
7+
8+
const server = new Server();
9+
10+
// BodyParser
11+
server.app.use( bodyParser.urlencoded({ extended: true }) );
12+
server.app.use( bodyParser.json() );
13+
14+
// CORS
15+
server.app.use( cors({ origin: true, credentials: true }) );
16+
17+
18+
// Rutas de servicios
19+
server.app.use('/', router );
20+
21+
22+
23+
24+
server.start( () => {
25+
console.log(`Servidor corriendo en el puerto ${ server.port }`);
26+
});
27+
28+

0 commit comments

Comments
 (0)