Skip to content
Snippets Groups Projects
Commit dc75b099 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

port primary and testing harness to new file organization

parent e9c205c7
No related branches found
No related tags found
No related merge requests found
*.sekret
*.sqlite
*.log
*~
\#*\#
.\#*
/var
const path = require('path'),
fs = require('fs'),
url = require('url'),
wsapi = require('./wsapi.js'),
httputils = require('./httputils.js'),
webfinger = require('./webfinger.js'),
wsapi = require('./lib/wsapi.js'),
httputils = require('./lib/httputils.js'),
webfinger = require('./lib/webfinger.js'),
sessions = require('cookie-sessions'),
secrets = require('./secrets.js');
secrets = require('./lib/secrets.js');
const STATIC_DIR = path.join(path.dirname(__dirname), "static");
// create the var directory if it doesn't exist
var VAR_DIR = path.join(__dirname, "var");
try { fs.mkdirSync(VAR_DIR, 0755); } catch(e) { }
const COOKIE_SECRET = secrets.hydrateSecret('cookie_secret', __dirname);
const STATIC_DIR = path.join(__dirname, "static");
function handler(request, response, serveFile) {
const COOKIE_SECRET = secrets.hydrateSecret('cookie_secret', VAR_DIR);
function handler(request, response, next) {
// dispatch!
var urlpath = url.parse(request.url).pathname;
if (urlpath === '/sign_in') {
serveFile(path.join(STATIC_DIR, "dialog", "index.html"), response);
request.url = "/dialog/index.html";
next();
} else if (/^\/wsapi\/\w+$/.test(urlpath)) {
try {
var method = path.basename(urlpath);
......@@ -38,13 +44,11 @@ function handler(request, response, serveFile) {
} else if (urlpath === "/code_update") {
console.log("code updated. shutting down.");
process.exit();
} else {
// node.js takes care of sanitizing the request path
if (urlpath == "/") urlpath = "/index.html"
serveFile(path.join(STATIC_DIR, urlpath), response);
}
};
exports.varDir = VAR_DIR;
exports.setup = function(app) {
var week = (7 * 24 * 60 * 60 * 1000);
app.use(sessions({
......
......@@ -3,7 +3,7 @@ const sqlite = require('sqlite'),
var db = new sqlite.Database();
db.open(path.join(path.dirname(__dirname), "userdb.sqlite"), function (error) {
db.open(path.join(path.dirname(__dirname), "var", "userdb.sqlite"), function (error) {
if (error) {
console.log("Couldn't open database: " + error);
throw error;
......
File moved
File moved
File moved
File moved
#!/usr/bin/env node
var sys = require("sys"),
http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs"),
express = require("express");
......@@ -13,13 +13,13 @@ var handler = require("./app.js");
var app = express.createServer();
app.use(express.logger({
stream: fs.createWriteStream(path.join(__dirname, "server.log"))
stream: fs.createWriteStream(path.join(handler.varDir, "server.log"))
}));
// let the specific server interact directly with the connect server to register their middleware
if (handler.setup) handler.setup(app);
// use the connect 'static' middleware for serving of static files (cache headers, HTTP range, etc)
app.use(express.static(path.join(path.dirname(__dirname), "static")));
app.use(express.static(path.join(__dirname, "static")));
app.listen(PRIMARY_PORT, PRIMARY_HOST);
......@@ -157,7 +157,7 @@ console.log("Running test servers:");
dirs.forEach(function(dirObj) {
if (!fs.statSync(dirObj.path).isDirectory()) return;
// does this server have a js handler for custom request handling?
var handlerPath = path.join(dirObj.path, "server", "app.js");
var handlerPath = path.join(dirObj.path, "app.js");
var runJS = {};
try {
var runJSExists = false;
......
/var
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment