Restructure project and add pm2 support
This commit is contained in:
parent
5618a6f645
commit
59386ab58f
23
pm2.json
Normal file
23
pm2.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"apps" : [
|
||||
{
|
||||
"name": "webapp",
|
||||
"cwd": "./webapp",
|
||||
"script": "./webapp/index.js",
|
||||
"watch": true,
|
||||
"env": {
|
||||
"PORT": "4100"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "worker1",
|
||||
"cwd": "./worker",
|
||||
"script": "./worker/index.js",
|
||||
"watch": true,
|
||||
"env": {
|
||||
"FARMER_URL": "http://localhost:4100"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
"use strict"
|
||||
|
||||
require("process").chdir(__dirname)
|
||||
|
||||
var app = require("express")()
|
||||
|
||||
// Support JSON and URL encoded bodies
|
||||
@ -11,6 +9,7 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
|
||||
extended: true
|
||||
}))
|
||||
|
||||
|
||||
// Caching for JSON APIs
|
||||
var apicache = require("apicache").options({ debug: false }).middleware
|
||||
|
||||
@ -29,6 +28,7 @@ var options = {
|
||||
// if an error occurred while rendering, show detail or not, default to false
|
||||
traceError: false
|
||||
}
|
||||
|
||||
app.set("view engine", "liquid")
|
||||
app.engine("liquid", expressLiquid(options))
|
||||
app.use(expressLiquid.middleware)
|
||||
@ -41,6 +41,6 @@ app.set("db", db)
|
||||
app.use(require("./controllers"))
|
||||
|
||||
// Start server
|
||||
app.listen(8080, "127.0.0.1", function () {
|
||||
app.listen(require("process").env.PORT, "127.0.0.1", function () {
|
||||
console.log("Minetest Mod Database listening on port 8080!")
|
||||
})
|
||||
|
@ -10,13 +10,14 @@ var sequelize = new Sequelize("database", "", "", {
|
||||
},
|
||||
|
||||
// SQLite only
|
||||
storage: "../db.sqlite"
|
||||
storage: "db.sqlite"
|
||||
})
|
||||
|
||||
var User = sequelize.define("user", {
|
||||
username: { type: Sequelize.STRING(100), unique: true }
|
||||
})
|
||||
|
||||
|
||||
var Mod = sequelize.define("mod", {
|
||||
basename: Sequelize.STRING(100),
|
||||
type: Sequelize.ENUM("mod", "game", "texturepack"),
|
||||
|
@ -18,12 +18,11 @@
|
||||
"homepage": "https://github.com/rubenwardy/minetest-mod-database#readme",
|
||||
"dependencies": {
|
||||
"apicache": "^0.7.4",
|
||||
"async": "^2.1.4",
|
||||
"body-parser": "^1.15.2",
|
||||
"express": "^4.14.0",
|
||||
"express-liquid": "^0.2.6",
|
||||
"github": "^8.1.0",
|
||||
"request": "^2.79.0",
|
||||
"sequelize": "^3.28.0",
|
||||
"sequelize": "^3.30.0",
|
||||
"sqlite3": "^3.1.8"
|
||||
}
|
||||
}
|
@ -1,13 +1,16 @@
|
||||
"use strict"
|
||||
|
||||
var request = require("request")
|
||||
var API_URL = "http://localhost:8080"
|
||||
|
||||
class FarmerAPI {
|
||||
constructor(url) {
|
||||
this.url = url
|
||||
}
|
||||
|
||||
getWork() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request.get({
|
||||
url: API_URL + '/workers/job',
|
||||
url: this.url + '/workers/job',
|
||||
qs: {
|
||||
token: "foobar"
|
||||
},
|
||||
@ -23,9 +26,9 @@ class FarmerAPI {
|
||||
}
|
||||
|
||||
sendResults(results) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request.post({
|
||||
url: API_URL + '/workers/job',
|
||||
url: this.url + '/workers/job',
|
||||
qs: {
|
||||
token: "foobar"
|
||||
},
|
@ -1,9 +1,8 @@
|
||||
"use strict"
|
||||
|
||||
require("process").chdir(__dirname)
|
||||
|
||||
const FarmerAPI = require("./farmerapi")
|
||||
const api = new FarmerAPI()
|
||||
|
||||
const api = new FarmerAPI(require("process").env.FARMER_URL)
|
||||
const fs = require("fs")
|
||||
const settings = JSON.parse(fs.readFileSync("settings.json", 'utf8'))
|
||||
|
22
worker/package.json
Normal file
22
worker/package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "minetest-mod-database-worker",
|
||||
"version": "0.1.0",
|
||||
"description": "Minetest Mod Database Worker",
|
||||
"main": "index.js",
|
||||
"scripts": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/rubenwardy/minetest-mod-database.git"
|
||||
},
|
||||
"author": "rubenwardy",
|
||||
"license": "LGPL-2.1+",
|
||||
"bugs": {
|
||||
"url": "https://github.com/rubenwardy/minetest-mod-database/issues"
|
||||
},
|
||||
"homepage": "https://github.com/rubenwardy/minetest-mod-database#readme",
|
||||
"dependencies": {
|
||||
"bluebird": "^3.4.7",
|
||||
"github": "^8.1.0",
|
||||
"request": "^2.79.0"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user