This repository has been archived by the owner on Oct 5, 2022. It is now read-only.
forked from jtremback/SF-Dev-Labs-Site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
95 lines (70 loc) · 2.14 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var express = require('express')
, format = require('util').format
, email = require("mailer")
, domainVar="sfdevlabs.com"
, sgusername = "slidescroll"
, sgpassword = "rambert123"
var app = module.exports = express()
app.use(express.bodyParser())
app.get('/', function(req, res){
res.send('Nada');
});
app.post('/', function(req, res, next){
console.log(req.body)
var article = req.body, body=""
body=""
for (art in article) {
console.log(article[art])
body+=art+": "
body+=article[art]+", "
};
email.send({
host: "smtp.sendgrid.net",
port: "587",
domain: domainVar,
to: "[email protected]",
from: "delivery@"+domainVar,
subject: "New SFDevLabs Lead",
body: body,
authentication: "login",
username: sgusername,
password: sgpassword
}, function(err, result){ });
res.setHeader('Location', 'http://sfdevlabs.com/');
res.send('<meta http-equiv="refresh" content="0; url=http://sfdevlabs.com/">');
});
if (!module.parent) {
app.listen(8080);
console.log('Express started on port 8080');
}
////
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 80;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
path.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, {"Content-Type": "text/plain"});
response.write("404 Not Found\n");
response.end();
return;
}
if (fs.statSync(filename).isDirectory()) filename += '/index.html';
fs.readFile(filename, "binary", function(err, file) {
if(err) {
response.writeHead(500, {"Content-Type": "text/plain"});
response.write(err + "\n");
response.end();
return;
}
response.writeHead(200);
response.write(file, "binary");
response.end();
});
});
}).listen(parseInt(port, 10));
console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");