Skip to content

Commit 3237c1c

Browse files
Merge branch 'master' of github.com:coding-blocks-archives/WebdevPitampura2019Fall
2 parents 9055efe + c85c5a1 commit 3237c1c

File tree

11 files changed

+504
-0
lines changed

11 files changed

+504
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Lecture12/express-intro/intro.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const express = require("express");
2+
3+
const app = express();
4+
5+
const middlewareGenerator = (num, pass = true) => (req, res, next) => {
6+
console.log("Middleware " + num)
7+
if (pass)
8+
next()
9+
}
10+
11+
const m1 = middlewareGenerator(1)
12+
const m2 = middlewareGenerator(2)
13+
const m3 = middlewareGenerator(3)
14+
const m4 = middlewareGenerator(4)
15+
const m5 = middlewareGenerator(5)
16+
17+
app.use(m1)
18+
19+
app.get('/a/b', (req, res, next) => {
20+
console.log("Exact Handler")
21+
next()
22+
})
23+
24+
app.use('/a', m2)
25+
app.use('/a/b', m3)
26+
app.use('/b', m4)
27+
app.use(m5)
28+
29+
30+
31+
32+
app.listen(8080, function() {
33+
console.log("Running on PORT: 8080");
34+
});

Lecture12/express-intro/misc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const express = require('express')
2+
const app = express()
3+
4+
5+
app.get('/courses/:id', (req, res) => {
6+
7+
res.send('You requested for ' + req.params.id)
8+
})
9+
10+
app.get('/search', (req, res) => {
11+
const stringGoogle = `https://google.com/search?q=` + req.query.str
12+
res.redirect(stringGoogle)
13+
})
14+
15+
app.listen(8080, function () {
16+
console.log("Runnning on 8080")
17+
})

0 commit comments

Comments
 (0)