-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (28 loc) · 935 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
33
34
35
36
37
38
39
40
/**
* Node Express JWT Example
*
* run with 'node ./server.js'
*/
const express = require('express');
const path = require('path');
const cors = require('cors');
const bodyParser = require('body-parser');
const apiUnprotected = require('./api-unprotected');
const apiProtected = require('./api-protected');
const { jwtLogin, jwtUnauthorizedError, jwtAuthorization } = require('./jwt-auth');
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use('/', express.static(path.join(__dirname, 'public')));
app.use('/login', jwtLogin);
app.use('/unprotected', apiUnprotected);
app.use("/protected",
jwtAuthorization,
jwtUnauthorizedError,
apiProtected);
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Node Express JWT Example listening on port ${PORT}`);
console.log(`ENVIRONMENT ${process.env.ENVIRONMENT}`)
console.log('Press Ctrl+C to quit.');
});