Skip to content

Commit

Permalink
update start in background
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-sapletta-com committed May 24, 2020
1 parent f4cec6e commit ea1ff83
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"os-homedir": "^1.0.2",
"papaparse": "^4.6.0",
"pug": "^2.0.4",
"shelljs": "^0.8.2"
"shelljs": "^0.8.2",
"forever": "^3.0.0"
},
"build": {
"appId": "com.electron.promagen-one",
Expand Down
12 changes: 10 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Start Express web app based on Express
const web = require('./src/web');
return new web();

// CONFIG
const PublicConfig = require('../config/projects');
var localConfig = new PublicConfig();

const web = require('./server/web');
return new web('PROMAGEN ONE ', 'localhost', localConfig.port, '../public');

// const web = require('./server/express');
// return new web('PROMAGEN ONE ', 'localhost', localConfig.port, '../public');
37 changes: 37 additions & 0 deletions server/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = function (application, domain = 'localhost', port = 3000, public_src = "./") {

const express = require('express');

const app = express();
port = process.env.PORT || port;

// NEW - Add CORS headers - see https://enable-cors.org/server_expressjs.html
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});

app.use(express.static(public_src));

// API endpoint
app.get("/api/ping", (req, res) => {
res.send({
msg: "Hello, World"
});
});


// app.get('/', (req, res) => {
// res.send('An alligator approaches!');
// });

// app.listen(PORT, () => console.log(`listening on ${PORT}`));
var url = 'http://' + domain + ':' + port;
app.listen(port, () => console.log(application + ' is listening on: ' + url));

return app;
};
11 changes: 4 additions & 7 deletions src/web.js → server/web.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function () {
module.exports = function (application, domain = 'localhost', port = 3000, public_src = "./") {

const createError = require('http-errors');
const express = require('express');
Expand All @@ -7,10 +7,6 @@ module.exports = function () {
const logger = require('morgan');
//const auth = require('./auth');

// CONFIG
const PublicConfig = require('../config/projects');
var localConfig = new PublicConfig();

//var FileList = [];
const indexRouter = require('../routes');
const batRouter = require('../routes/bat');
Expand All @@ -33,7 +29,8 @@ module.exports = function () {
web.use(express.json());
web.use(express.urlencoded({extended: false}));
web.use(cookieParser());
var public_path = path.join(__dirname, '../public');

var public_path = path.join(__dirname, public_src);
console.log('public_path', public_path);
web.use(express.static(public_path));

Expand All @@ -60,7 +57,7 @@ module.exports = function () {
res.render('error', {title: title});
});

web.listen(localConfig.port);
web.listen(port);

return web;
};
3 changes: 2 additions & 1 deletion start.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WHERE node
IF %ERRORLEVEL% NEQ 0 (
echo nodejs is not installed on this system!
) else (
node server.js
::node server.js
forever start server.js
)

3 changes: 2 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
#dir_path=$(dirname $full_path)
#echo $dir_path
#node $dir_path/server.js
node server.js
#node server.js
forever start server.js

0 comments on commit ea1ff83

Please sign in to comment.