You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
7 years ago
|
'use strict';
|
||
|
|
||
|
const express = require("express");
|
||
|
const expressWs = require("express-ws");
|
||
|
const knex = require("knex");
|
||
|
const path = require("path");
|
||
|
const bodyParser = require("body-parser");
|
||
|
|
||
|
let db = knex(require("./knexfile"));
|
||
|
let imageStore = require("./lib/image-store")(path.join(__dirname, "./images"));
|
||
|
let taskTracker = require("./lib/tasks/tracker")();
|
||
|
|
||
|
let state = {db, imageStore, taskTracker};
|
||
|
|
||
|
let app = express();
|
||
|
expressWs(app);
|
||
|
|
||
|
app.set("view engine", "pug");
|
||
|
app.set("views", path.join(__dirname, "views"));
|
||
|
|
||
|
app.use((req, res, next) => {
|
||
|
res.locals.isUnderPrefix = function isUnderPrefix(path, resultingClass) {
|
||
|
// FIXME: Proper path segment parsing...
|
||
|
if (req.originalUrl.indexOf(path) === 0) {
|
||
|
return resultingClass;
|
||
|
} else {
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
next();
|
||
|
});
|
||
|
|
||
|
app.use(express.static(path.join(__dirname, "public")));
|
||
|
|
||
|
app.use(bodyParser.urlencoded({
|
||
|
extended: true
|
||
|
}));
|
||
|
|
||
|
app.use(require("./routes/index"));
|
||
|
app.use("/disk-images", require("./routes/disk-images")(state));
|
||
|
app.use("/instances", require("./routes/instances")(state));
|
||
|
|
||
|
app.use((err, req, res, next) => {
|
||
|
res.render("error", {
|
||
|
error: err
|
||
|
});
|
||
|
});
|
||
|
|
||
|
app.listen(3000).on("listening", () => {
|
||
|
console.log("Listening...");
|
||
|
});
|