-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
99 lines (88 loc) · 2.8 KB
/
server.js
File metadata and controls
99 lines (88 loc) · 2.8 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var express = require('express');
var path = require("path");
var app = express();
var expressStaticGzip = require('express-static-gzip');
app.use(express.static(path.join(__dirname, '/dist/IMS-client'))); // myApp will be the same folder name.
// app.get('/', function (req, res, next) {
// res.redirect('/');
// });
// app.use("/", path.join(__dirname, '/dist/IMS-client/'));
// app.use('/app', function(req, res) {
// res.sendFile(path.join(__dirname, '/dist/IMS-client/index.html')); // load the single view file (angular will handle the page changes on the front-end)
// });
app.use('/app', expressStaticGzip(path.join(__dirname, '/dist/IMS-client')));
// app.use('*', function(req, res) { res.redirect('/app')});
app.all('*', function(req, res, next){
//preflight needs to return exact request-header
res.set('Access-Control-Allow-Headers', req.headers['access-control-request-headers']);
if ('OPTIONS' == req.method) return res.sendStatus(204);
next();
});
app.use('*', function(req, res, next){
//preflight needs to return exact request-header
res.sendFile(path.join(__dirname, '/dist/IMS-client/index.html'))
});
app.listen(4222, 'localhost');
console.log('MyProject Server is Listening on port 4222');
// const express = require("express");
// const http = require("http");
// const path = require("path");
//
// const app = express();
//
// const port = process.env.PORT || 4200;
//
// app.use(express.static(__dirname + "/dist/IMS-client"));
//
// app.get("/*", (req, res) => {
// res.sendFile(path.join(__dirname))
// });
//
// app.get("/", (req, res, next) => {
// res.sendFile("index.html", { root: __dirname + "Client"});
// });
//
//
// const server = http.createServer(app);
//
// server.listen(port, () => console.log('Running....'));
// ==============================================
//
// var express = require('express'),
// path = require('path'),
// fs = require('fs');
// var compression = require('compression');
// var app = express();
// var staticRoot = __dirname + "/dist/IMS-client/";
// var env = process.env.NODE_ENV || 'development';
//
// app.set('port', (process.env.PORT || 5000));
//
// app.use(compression());
// /* other middleware */
//
// /* place any backend routes you have here */
//
// app.use(function(req, res, next) {
// //if the request is not html then move along
// var accept = req.accepts('html', 'json', 'xml');
// if (accept !== 'html') {
// return next();
// }
//
// // if the request has a '.' assume that it's for a file, move along
// var ext = path.extname(req.path);
// if (ext !== '') {
// return next();
// }
//
// fs.createReadStream(staticRoot + 'index.html').pipe(res);
//
// });
//
// app.use(express.static(staticRoot));
//
//
// app.listen(app.get('port'), function() {
// console.log('app running on port', app.get('port'));
// });