forked from steveblue/angular2-rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
46 lines (29 loc) · 1.02 KB
/
router.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
// router.js
const express = require('express');
const router = require('express').Router();
const compression = require('compression');
const config = require('./ngr.config.js');
module.exports = function(app) {
'use strict';
// ROUTER CONFIG
app.use(function(req, res, next) {
// CAUTION: Wide open CORS!
res.header('Access-Control-Allow-Origin', req.headers.origin);
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type');
if (req.method == 'OPTIONS' ) {
res.send(200);
}
else {
next();
}
});
// ROUTES
app.use(compression());
app.use('/', express.static( process.cwd() + '/' + config.build ));
app.get('*', function (req, res) {
res.sendFile('index.html', { root: process.cwd() + '/' + config.build });
});
return router;
};