Skip to content

Commit

Permalink
created boilerplate express server integrated with electron
Browse files Browse the repository at this point in the history
  • Loading branch information
beatface committed Mar 11, 2016
1 parent 1bab212 commit 3d47a66
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "public/lib"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ node_modules

# Optional REPL history
.node_repl_history

public/lib/*
6 changes: 6 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"esversion": 6,
"strict": true,
"esnext": false,
"node": true
}
21 changes: 21 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "dashbored",
"description": "Dashbored is an all-in-one dashboard for users to keep notes, track the weather, get news updates, etc. Built with Express, Angular, Node, and SQLite.",
"main": "server.js",
"authors": [
"“Emma <“[email protected]”>"
],
"license": "MIT",
"homepage": "https://github.com/beatface/dashbored",
"moduleType": [],
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "^1.5.0"
}
}
Empty file added nodemon.json
Empty file.
50 changes: 50 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "dashbored",
"version": "1.0.0",
"description": "Dashbored is an all-in-one dashboard for users to keep notes, track the weather, get news updates, etc. Built with Express, Angular, Node, and SQLite.",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron server.js",
"dev": "NODE_ENV=development electron server.js",
"bower": "./node_modules/bower/bin/bower"
},
"repository": {
"type": "git",
"url": "git+https://github.com/beatface/dashbored.git"
},
"keywords": [],
"author": "“Emma <“[email protected]”>",
"license": "MIT",
"bugs": {
"url": "https://github.com/beatface/dashbored/issues"
},
"eslintConfig": {
"env": {
"node": true,
"es6": true,
"browser": true
},
"extends": "eslint:recommended",
"globals": {
"res": true,
"next": true
},
"rules": {
"no-console": 0,
"comma-dangle": 0
}
},
"homepage": "https://github.com/beatface/dashbored#readme",
"dependencies": {
"body-parser": "^1.15.0",
"electron-prebuilt": "^0.36.10",
"express": "^4.13.4",
"jade": "^1.11.0",
"node-sass-middleware": "^0.9.7"
},
"devDependencies": {
"bower": "^1.7.7",
"nodemon": "^1.9.1"
}
}
Empty file added public/app.js
Empty file.
Empty file added public/styles/styles.css
Empty file.
Empty file added public/styles/styles.sass
Empty file.
11 changes: 11 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

const express = require('express');
const router = express.Router();

router.get('/', (req, res) => {
res.send('This seems to be working!');
});


module.exports = router;
80 changes: 80 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use strict";

const electron = require('electron');
const electronApp = electron.app;
const BrowserWindow = electron.BrowserWindow;

const express = require('express');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3153;

// Express routes, views, ctrls
const routes = require('./routes/');

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;

// Quit when all windows are closed.
electronApp.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform != 'darwin') {
electronApp.quit();
}
});

app.use(express.static(path.join(__dirname, 'public')));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(routes);

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
electronApp.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow({
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: false
},
width: 840,
height: 600
});

// development error handler
// will print stacktrace
if (process.env.NODE_ENV === 'development') {
app.use(function(err, req, res) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});

app.listen(PORT, () => {
// and load the index.html of the electronApp.
mainWindow.loadURL('http://127.0.0.1:3153');
// Open the DevTools.
mainWindow.webContents.openDevTools();
});

// closes server when window is closed
mainWindow.on('closed', function() {
mainWindow = null;
});
});
Empty file added start-electron.js
Empty file.
6 changes: 6 additions & 0 deletions views/error.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends template.jade

block content
h1= message
h2= error.status
pre #{error.stack}
9 changes: 9 additions & 0 deletions views/template.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

doctype html
html(lang="en")
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
//- script(src="/components/jquery/dist/jquery.min.js")
body
block content

0 comments on commit 3d47a66

Please sign in to comment.