forked from resgateio/resgate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (26 loc) · 988 Bytes
/
server.js
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
32
const express = require('express');
const jwt = require('jsonwebtoken');
// Load authService.js and exampleService.js
// Both may run as independent micro-services
require("./authService.js");
require("./exampleService.js");
const mySecret = 'shhhhh';
const jwtCookieName = 'access-token';
// Create a simple webserver to serve the client.
let app = express();
// Accessing /login will set a JWT token in a cookie
app.get('/login', (req, res) => {
let token = jwt.sign({ foo: 'bar' }, mySecret);
res.cookie(jwtCookieName, token);
res.send('The access-token cookie is now set. <a href="/">Go back</a>');
});
// Accessing /logout will clear the JWT token cookie
app.get('/logout', (req, res) => {
res.clearCookie(jwtCookieName);
res.send('The access-token cookie is now cleared. <a href="/">Go back</a>');
});
// Serve index.html and start listening
app.use('/', express.static(__dirname));
app.listen(8084, () => {
console.log('Client available at http://localhost:8084');
});