-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (21 loc) · 774 Bytes
/
server.js
File metadata and controls
28 lines (21 loc) · 774 Bytes
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
var express = require("express")
var app = express()
var http = require("http").Server(app)
var path = require("path")
var events = require("events")
exports.events = new events()
exports.on = exports.events.on.bind(exports.events)
// expose get and post requests
exports.get = app.get.bind(app)
exports.post = app.post.bind(app)
exports.listen = app.listen.bind(app)
// add support for post requests
var bodyParser = require("body-parser")
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
// a default home page
app.get("/", function(req, res){
res.sendFile( path.join(__dirname, "public/index.html") );
});
// a default public directory
app.use("/", express.static("public"));