-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (31 loc) · 1.38 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
// dependencies ------------------------------------------------------------------------------
var express = require('express');
var app = express();
// configuration -----------------------------------------------------------------------------
app.use(function (req, res, next) {
// allow CORS
res.setHeader('Access-Control-Allow-Origin', '*');
// allowed methods
res.setHeader('Access-Control-Allow-Methods', '*');
// request headers
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// allow session credentials
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
// routing -----------------------------------------------------------------------------------
/**
* All requests to static files in the app/ directory will be served.
* All other requests will return index.html.
* This allows us to remove the # from angular routing with functional page refreshes.
*/
app.use(express.static(__dirname + '/app'));
app.get('*',function(req,res){
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
res.sendFile('/index.html', {root:__dirname + '/app'});
});
// server ------------------------------------------------------------------------------------
app.listen(3000, function() {
console.log("Listening on 3000");
});