Skip to content

Commit d8b1e18

Browse files
committed
Express example.
1 parent 4896754 commit d8b1e18

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

example/controller.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Context = require('../src');
2+
3+
class UserController {
4+
get(req, res) {
5+
res.send(Context.get());
6+
}
7+
}
8+
9+
module.exports = new UserController();

example/middleware.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Context = require('../src');
2+
3+
module.exports = (req, res, next) => {
4+
Context.create({
5+
val: true
6+
});
7+
next();
8+
};

example/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "sample-express-server",
3+
"version": "1.0.0",
4+
"description": "sample",
5+
"main": "server.js",
6+
"scripts": {
7+
"start": "node server.js"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/ceroloy/sample-express-app"
12+
},
13+
"keywords": [
14+
"IBM",
15+
"Cloud"
16+
],
17+
"author": "IBM",
18+
"license": "Apache-2.0",
19+
"dependencies": {
20+
"express": "^4.16.2",
21+
"node-execution-context": "^1.0.1"
22+
}
23+
}

example/server.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const express = require('express');
2+
const UserController = require('./controller');
3+
const ContextMiddleware = require('./middleware');
4+
5+
const app = express();
6+
7+
app.get('/', function(req,res){
8+
res.sendFile(__dirname + '/static/index.html');
9+
});
10+
11+
const port = process.env.PORT || 8080;
12+
13+
app.use('/', ContextMiddleware);
14+
15+
app.get('/user', UserController.get);
16+
17+
app.listen(port, function(){
18+
console.log("Server is running");
19+
});

example/static/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
</head>
7+
8+
<body>
9+
10+
</body>
11+
<footer></footer>
12+
</html>

0 commit comments

Comments
 (0)