-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
365 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// router.js | ||
|
||
const express = require('express'); | ||
const router = require('express').Router(); | ||
const compression = require('compression'); | ||
const config = require(process.cwd()+'/angular.json'); | ||
|
||
|
||
module.exports = function(app) { | ||
'use strict'; | ||
let projectRoot = config.projects[config.defaultProject].architect.build.options.outputPath; | ||
// 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() + '/' + projectRoot )); | ||
|
||
|
||
app.get('*', function (req, res) { | ||
res.sendFile('index.html', { root: process.cwd() + '/' + projectRoot }); | ||
}); | ||
|
||
|
||
|
||
return router; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"use strict"; | ||
// server.js | ||
|
||
const express = require('express'); | ||
const http = require('http'); | ||
const fs = require('fs'); | ||
const app = express(); | ||
const config = require(process.cwd()+'/angular.json'); | ||
const serverConfig = { | ||
dev: require(process.cwd()+'/config/server.config.dev.js'), | ||
prod: require(process.cwd()+'/config/server.config.prod.js') | ||
}; | ||
|
||
let projectRoot = config.projects[config.defaultProject].architect.build.options.outputPath; | ||
let env = process.env.NODE_ENV || 'dev'; | ||
const port = serverConfig[env].port || process.env.PORT; | ||
const host = serverConfig[env].origin; | ||
let canWatch = false; | ||
let server; | ||
|
||
process.argv.forEach(function(arg){ | ||
|
||
if (arg.includes('watch')) { | ||
canWatch = arg.split('=')[1].trim() === 'true' ? true : false; | ||
} | ||
|
||
}); | ||
|
||
|
||
// Livereload Server Start | ||
|
||
let live = function() { | ||
let livereload = require('livereload'); | ||
let liveserver = livereload.createServer({ | ||
port: 35729 | ||
}); | ||
liveserver.watch([process.cwd() + '/'+projectRoot+'/assets', | ||
process.cwd() + '/'+projectRoot+'/src', | ||
process.cwd() + '/'+projectRoot+'/style', | ||
process.cwd() + '/'+projectRoot+'/*.html', | ||
process.cwd() + '/'+projectRoot+'/*.js', | ||
process.cwd() + '/'+projectRoot+'/*.css']); | ||
console.log('Livereload available at '+host+':'+35729); | ||
}; | ||
|
||
// Create Server | ||
|
||
server = http.createServer(app); | ||
|
||
if (canWatch === true) { | ||
|
||
live(); | ||
|
||
} | ||
|
||
|
||
// Express Middleware | ||
|
||
|
||
|
||
// Load Modules | ||
|
||
const routes = require('./router')(app); | ||
|
||
// Server Start | ||
|
||
server.listen(port); | ||
|
||
console.log('Express available at '+host+':'+port); | ||
|
||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const config = { | ||
origin: 'localhost', | ||
port: 4200 | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const config = { | ||
origin: 'localhost', | ||
port: 4200 | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.