archive
/
tstatic
Archived
1
Fork 0

Remove old files

This commit is contained in:
Jake Howard 2017-02-14 21:24:35 +00:00
parent 9933f7574e
commit 4189d95b8b
7 changed files with 0 additions and 166 deletions

View File

@ -1,9 +0,0 @@
const staticFile = require('connect-static-file');
const path = require('path');
const { SERVE_DIR } = require('./consts');
const handle404 = staticFile(path.join(SERVE_DIR, '.404.html'));
module.exports = function (request, response, next) {
response.statusCode = 404;
return handle404(request, response, next);
};

View File

@ -1,17 +0,0 @@
const basicAuth = require('express-basic-auth');
const { BASIC_AUTH_ENABLED } = require('./consts');
function basicAuthHandler(username, password) {
return process.env.BASIC_AUTH_USERNAME === username && process.env.BASIC_AUTH_PASSWORD === password;
}
if (BASIC_AUTH_ENABLED) {
module.exports = basicAuth({
authorizer: basicAuthHandler,
challenge: true
});
} else {
module.exports = (req, res, next) => next();
}

View File

@ -1,11 +0,0 @@
const IN_TEST = process.env.NODE_ENV === 'test';
module.exports = {
SERVE_DIR: IN_TEST ? 'site/' : process.argv[process.argv.length - 1],
PORT: process.env.PORT || 5000,
ALLOWED_IPS: process.env.ALLOWED_IPS ? process.env.ALLOWED_IPS.split(',') : undefined,
IN_TEST,
IN_PRODUCTION: process.env.NODE_ENV === 'production',
DIR_LIST: process.env.DIR_LIST,
BASIC_AUTH_ENABLED: process.env.BASIC_AUTH_USERNAME && process.env.BASIC_AUTH_PASSWORD
};

View File

@ -1,17 +0,0 @@
const winston = require('winston');
const expressWinston = require('express-winston');
module.exports = expressWinston.logger({
transports: [
new winston.transports.Console({
colorize: true
})
],
meta: false,
msg: '{{ req.url }} '
.concat('status:{{ res.statusCode }} ')
.concat('useragent:{{ req.headers["user-agent"] }} ')
.concat('time:{{ res.responseTime }}ms'),
colorize: true,
statusLevels: true
});

View File

@ -1,54 +0,0 @@
#!/usr/bin/env node
console.log('Starting Server...');
const app = require('express')();
const consts = require('./consts');
const compression = require('compression');
const helmet = require('helmet');
const serveIndex = require('serve-index');
const AccessControl = require('express-ip-access-control');
const opbeat = require('opbeat').start({
active: consts.IN_PRODUCTION
});
const logging = require('./logging');
const staticFiles = require('./static-files');
const handle404 = require('./404');
const basicAuth = require('./basic-auth');
if (consts.ALLOWED_IPS) {
app.set('trust proxy', true);
app.use(AccessControl({
mode: 'allow',
allows: consts.ALLOWED_IPS,
statusCode: 404
}));
}
// Custom Middleware
app.use(logging);
app.use(basicAuth);
if (consts.DIR_LIST) {
app.use(serveIndex(consts.SERVE_DIR, {
icons: true
}));
} else {
app.use(staticFiles.indexHandle);
}
app.use(staticFiles.static);
app.use(handle404);
// Library
app.use(compression({ level: 9 }));
app.use(helmet());
app.use(opbeat.middleware.express());
const server = app.listen(consts.PORT, function () {
console.log('Server started on ' + server.address().port);
});
module.exports = server;

View File

@ -1,16 +0,0 @@
const express = require('express');
const path = require('path');
const { SERVE_DIR } = require('./consts');
module.exports.indexHandle = function (request, response, next) {
if (request.url.endsWith('/')) {
request.url = path.join(request.url, 'index.html');
}
next();
};
module.exports.static = express.static(SERVE_DIR, {
dotfiles: 'ignore',
index: false,
redirect: true
});

View File

@ -1,42 +0,0 @@
const request = require('supertest');
const fs = require('fs');
describe('Server', function () {
var server;
before(function () {
server = require('../src/server');
});
after(function () {
server.close();
});
it('responds to /', function (done) {
request(server)
.get('/')
.expect(200, done);
});
it('returns 404 on bad path', function (done) {
request(server)
.get('/foo/bar')
.expect(404, done);
});
describe('index route', function () {
const body = fs.readFileSync(__dirname + '/../site/index.html').toString();
it('should render /index.html', function (done) {
request(server)
.get('/index.html')
.expect(200, body, done);
});
it('should render /', function (done) {
request(server)
.get('/')
.expect(200, body, done);
});
});
});