-
Notifications
You must be signed in to change notification settings - Fork 394
/
Copy pathserver.ts
34 lines (19 loc) · 844 Bytes
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as express from 'express';
import {Application} from "express";
import {getAllCourses, getCourseById} from "./get-courses.route";
import {searchLessons} from "./search-lessons.route";
import {saveCourse} from './save-course.route';
import {loginUser} from './login.route';
const bodyParser = require('body-parser');
const app: Application = express();
app.use(bodyParser.json());
const cors = require('cors');
app.use(cors({origin: true}));
app.route('/api/courses').get(getAllCourses);
app.route('/api/courses/:id').get(getCourseById);
app.route('/api/lessons').get(searchLessons);
app.route('/api/courses/:id').put(saveCourse);
app.route('/api/login').post(loginUser);
const httpServer = app.listen(9000, () => {
console.log("HTTP REST API Server running at http://localhost:" + httpServer.address()["port"]);
});