-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver.js
58 lines (49 loc) · 1.52 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const WeeblyMiddleware = require('./middleware/weebly.js');
const oauthRouter = require('./app/oauth-router.js');
const webhooksRouter = require('./app/webhooks-router.js');
const getDate = require('./outputDate.js');
/**
* Create the express app
*/
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
/**
* Set and create a new instance of WeeblyMiddleware.
* The `client_id` and `secret_key` can be set either here
* or in your environment variables (e.g. for Heroku)
*
* NOTE: If you have WEEBLY_CLIENT_ID and WEEBLY_SECRET_KEY
* set in your environment, you can create the new WeeblyMiddleware
* instance with `const wMiddleware = new WeeblyMiddleware()`
*
* @type {WeeblyMiddleware|exports|module.exports}
*/
const wMiddleware = new WeeblyMiddleware({
'client_id': '',
'secret_key': ''
});
/**
* Requires Weebly Dev secrets to be set to access
*/
app.use('/oauth', wMiddleware, oauthRouter);
app.use('/webhooks', wMiddleware, webhooksRouter);
/**
* Does not require weebly tokens to access
*/
app.get('/', function(req, res) {
//console.log(`Date: ${getDate()}`);
//console.log(`Received request at webroot of app`);
res.sendFile(path.resolve(`${__dirname}/messages/messages.txt`));
});
/**
* Listen on environment port or 3000
*/
app.listen(process.env.PORT || 3000);
console.log(`\nListening on http://localhost:${process.env.PORT || 3000}\n`);