-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (26 loc) · 815 Bytes
/
server.js
File metadata and controls
35 lines (26 loc) · 815 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
29
30
31
32
33
34
35
'use strict';
var express = require('express');
var cors = require('cors');
var app = express();
// allow Cross Origin requests, for testing
app.use(cors());
app.use('/public', express.static(process.cwd() + '/public'));
// get ip infos even if passing through a proxy like here
app.enable('trust proxy');
app.route('/')
.get(function (req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});
app.route('/api/whoami')
.get(function(req, res){
res.json({ipaddress: req.ip, language: req.headers['accept-language'], software: req.headers['user-agent']});
});
// 404 Not Found Middleware
app.use(function(req, res, next) {
res.status(404)
.type('text')
.send('Not Found');
})
app.listen(process.env.PORT || 3000, function () {
console.log('Node.js listening ...');
});