-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
34 lines (28 loc) · 916 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
"use strict";
/**
* Express web server configured to host ST Schema connector
*/
require('dotenv').config();
const express = require('express')
const connector = require('./connector')
const PORT = process.env.PORT || 3000
const ACCESS_TOKEN_PREFIX = process.env.ACCESS_TOKEN_PREFIX;
const server = express();
server.use(express.json());
server.post('/', (req, res) => {
if (accessTokenIsValid(req, res)) {
connector.handleHttpCallback(req, res)
}
});
function accessTokenIsValid(req, res) {
// Replace with proper validation of issued access token. This version just checks for the
// profix defined in the summy OAuth server
if (req.body.authentication.token.startsWith(ACCESS_TOKEN_PREFIX)) {
return true;
}
console.log('Unauthorized request')
res.status(401).send('Unauthorized')
return false;
}
server.listen(PORT);
console.log(`Server listening on http://127.0.0.1:${PORT}`);