forked from marcos-abreu/kamu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (38 loc) · 1.39 KB
/
index.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
'use strict';
// built-in/third-party modules
var Http = require( 'http' );
// custom modules
var config = require( './src/config' ),
connStatus = require( './src/connection' ),
app = require( './src' );
// start tracking connections
connStatus.start();
var server = Http.createServer( function( req, res ) {
// only get requests with a url pathname
if ( req.method !== 'GET' || req.url === '/' ) {
res.writeHead( 301, { ...config.defaultHeaders, 'Location': 'https://www.wattpad.com' });
return res.end();
}
// favicon requests will get a straight response
else if ( req.url === '/favicon.ico' ) {
res.writeHead( 200, config.defaultHeaders );
return res.end( 'ok' );
}
// status request will give you the amount of connections
else if ( req.url === '/status' ) {
res.writeHead( 200, config.defaultHeaders );
return res.end( 'ok: ' + connStatus.toString() );
}
// if the request passed the first set of filters than process the request
else {
connStatus.open();
return app.processRequest( req, res );
}
} );
// log indicating that the server is ready to receive requests
console.log( config.name + ' ssl image proxy running on ' + config.port + ' ' +
'with pid: ' + process.pid + ' ' +
'version:' + config.version + '.' );
// start listening for requests
server.listen( config.port );
module.exports = server;