First commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.settings/*
|
||||||
|
server/node_modules/*
|
||||||
24
.project
Normal file
24
.project
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Lumberjack-GraphQL</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||||
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
5
server/.env
Normal file
5
server/.env
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
DB_HOST=localhost
|
||||||
|
DB_USER=website
|
||||||
|
DB_PASSWORD=henrypump
|
||||||
|
DB_DATABASE=lumberjack
|
||||||
|
DB_TEST_DATABASE=test_lumberjack
|
||||||
41
server/index.js
Normal file
41
server/index.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
var express = require('express');
|
||||||
|
var app = express();
|
||||||
|
var morgan = require('morgan');
|
||||||
|
var bodyParser = require('body-parser');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
app.use(express.static(__dirname + "/public"));
|
||||||
|
app.use(morgan('dev'));
|
||||||
|
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
app.use(bodyParser.urlencoded({
|
||||||
|
extended: true
|
||||||
|
}));
|
||||||
|
|
||||||
|
//Models
|
||||||
|
var models = require("./models");
|
||||||
|
|
||||||
|
//Sync Database
|
||||||
|
models.sequelize.sync().then(function() {
|
||||||
|
console.log('Nice! Database looks fine');
|
||||||
|
}).catch(function(err) {
|
||||||
|
console.log(err, "Something went wrong with the Database Update!");
|
||||||
|
});
|
||||||
|
|
||||||
|
// app.get('/', require('./routes').index);
|
||||||
|
// app.get('/deviceTypes', require('./routes').deviceTypes);
|
||||||
|
// app.get('/devices/:deviceId/values', require('./routes').channelValues);
|
||||||
|
// app.get('/devices', require('./routes').devices);
|
||||||
|
// app.get('/companies', require('./routes').companies);
|
||||||
|
// app.get('/alldata', require('./routes').getAllData);
|
||||||
|
// app.post('/login', require('./routes').login);
|
||||||
|
// app.get('/login', require('./routes').getLogin);
|
||||||
|
// app.get('/logout', require('./routes').logout);
|
||||||
|
|
||||||
|
app.listen(3000, function () {
|
||||||
|
console.log('Listening on port 3000!')
|
||||||
|
})
|
||||||
|
|
||||||
16
server/models/Device.js
Normal file
16
server/models/Device.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
module.exports = function(sequelize, DataTypes) {
|
||||||
|
var Device = sequelize.define("Device", {
|
||||||
|
name: DataTypes.STRING,
|
||||||
|
deviceType: sequelize.models.DeviceType,
|
||||||
|
address: DataTypes.STRING
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
Device.associate = function(models) {
|
||||||
|
// Using additional options like CASCADE etc for demonstration
|
||||||
|
// Can also simply do Task.belongsTo(models.User);
|
||||||
|
Device.hasOne(models.DeviceType);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Device;
|
||||||
|
};
|
||||||
13
server/models/DeviceType.js
Normal file
13
server/models/DeviceType.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = function(sequelize, DataTypes) {
|
||||||
|
var DeviceType = sequelize.define("DeviceType", {
|
||||||
|
name: DataTypes.STRING
|
||||||
|
});
|
||||||
|
|
||||||
|
DeviceType.associate = function(models) {
|
||||||
|
// Using additional options like CASCADE etc for demonstration
|
||||||
|
// Can also simply do Task.belongsTo(models.User);
|
||||||
|
DeviceType.belongsTo(models.Device);
|
||||||
|
};
|
||||||
|
|
||||||
|
return DeviceType;
|
||||||
|
};
|
||||||
47
server/models/index.js
Normal file
47
server/models/index.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// ./models/index.js
|
||||||
|
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require("path");
|
||||||
|
var Sequelize = require('sequelize');
|
||||||
|
|
||||||
|
var dbOptions = {
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
username: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
database: process.env.DB_DATABASE,
|
||||||
|
dialect: 'mysql'
|
||||||
|
};
|
||||||
|
|
||||||
|
var sequelize = new Sequelize(dbOptions);
|
||||||
|
var db = {};
|
||||||
|
|
||||||
|
|
||||||
|
var deviceType = sequelize.import('./DeviceType.js');
|
||||||
|
db.deviceType = deviceType;
|
||||||
|
|
||||||
|
var device = sequelize.import('./Device.js');
|
||||||
|
db.device = device;
|
||||||
|
|
||||||
|
|
||||||
|
// db.deviceType.associate(db);
|
||||||
|
// db.device.associate(db);
|
||||||
|
|
||||||
|
// fs.readdirSync(__dirname)
|
||||||
|
// .filter(function(file) {
|
||||||
|
// return (file.indexOf(".") !== 0) && (file !== "index.js");
|
||||||
|
// })
|
||||||
|
// .forEach(function(file) {
|
||||||
|
// var model = sequelize.import(path.join(__dirname, file));
|
||||||
|
// db[model.name] = model;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// Object.keys(db).forEach(function(modelName) {
|
||||||
|
// if ("associate" in db[modelName]) {
|
||||||
|
// db[modelName].associate(db);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
db.sequelize = sequelize;
|
||||||
|
db.Sequelize = Sequelize;
|
||||||
|
|
||||||
|
module.exports = db;
|
||||||
1048
server/package-lock.json
generated
Normal file
1048
server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
server/package.json
Normal file
33
server/package.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "lumberjack",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Datalogger Web Server for PLC data",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "mocha"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/Henry-Pump/Lumberjack-GraphQL.git"
|
||||||
|
},
|
||||||
|
"author": "Patrick McDonagh, Henry Pump",
|
||||||
|
"license": "ISC",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/Henry-Pump/Lumberjack-GraphQL/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/Henry-Pump/Lumberjack-GraphQL#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"body-parser": "^1.18.2",
|
||||||
|
"dotenv": "^4.0.0",
|
||||||
|
"express": "^4.16.1",
|
||||||
|
"graphql": "^0.11.6",
|
||||||
|
"graphql-sequelize": "^5.4.2",
|
||||||
|
"morgan": "^1.9.0",
|
||||||
|
"mysql": "^2.14.1",
|
||||||
|
"mysql2": "^1.4.2",
|
||||||
|
"sequelize": "^4.13.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"mocha": "^3.5.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user