-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (38 loc) · 1.48 KB
/
app.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
/*
* EXPRESS CONFIGURATION FILE
*/
'use strict'
const express = require('express')
const compression = require('compression');
const bodyParser = require('body-parser');
const app = express()
app.use(compression());
const api = require ('./routes')
const path = require('path')
//CORS middleware
function setCrossDomain(req, res, next) {
//instead of * you can define ONLY the sources that we allow.
res.header('Access-Control-Allow-Origin', '*');
//http methods allowed for CORS.
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Access-Control-Allow-Origin, Accept, Accept-Language, Origin, User-Agent');
//res.header('Access-Control-Allow-Headers', '*');
next();
}
app.use(bodyParser.urlencoded({limit: '50mb', extended: false}))
app.use(bodyParser.json({limit: '50mb'}))
app.use(setCrossDomain);
// use the forward slash with the module api api folder created routes
app.use('/api',api)
app.use('/apidoc',express.static('apidoc', {'index': ['index.html']}))
/*app.use(express.static(path.join(__dirname, 'apidoc')));*/
/*app.get('/doc', function (req, res) {
res.sendFile('apidoc/index.html', { root: __dirname });
});*/
//ruta angular, poner carpeta dist publica
app.use(express.static(path.join(__dirname, 'dist')));
// Send all other requests to the Angular app
app.get('*', function (req, res, next) {
res.sendFile('dist/index.html', { root: __dirname });
});
module.exports = app