forked from leftlogic/twitter-proxy
-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
49 lines (42 loc) · 1.19 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
'use strict';
module.exports = function startTwitterProxyServer(config) {
/**
* Setup the server
*/
let express = require('express'),
http = require('http'),
app = express();
let proxy = require('./proxy');
// Save the config for use later
app.set('config', config);
// All environments
app.set('port', config.port || 7890);
// Logging
app.use(express.logger('dev'));
// gzip
app.use(express.compress());
// Body parsing
app.use(express.json());
app.use(express.urlencoded());
// CORS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header('Content-Type', 'application/javascript');
if (req.method === 'OPTIONS')
return res.send(200);
next();
});
// Express routing
app.use(app.router);
// Set up the routes
proxy.route(app);
/**
* Get the party started
*/
http.createServer(app)
.listen(app.get('port'), function () {
console.log('twitter-proxy server ready: http://localhost:' + app.get('port'));
});
};