Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const app = express();
const fs = require('fs');
const path = require('path');

// setup port
app.set('port', (process.env.PORT || 5000));
Expand All @@ -25,23 +26,23 @@ let manufacturersIndex = null;
let typesIndex = null;

// read in the JSON files to fill those data structures
fs.readFile('fixtures/manufacturers.json', 'utf8', (error, data) => {
fs.readFile(path.join(__dirname, 'fixtures', 'manufacturers.json'), 'utf8', (error, data) => {
if (error) {
addFileReadError('There was an error reading in the manufacturer data.', error);
return;
}

manufacturers = JSON.parse(data);
});
fs.readFile('fixtures/index_manufacturers.json', 'utf8', (error, data) => {
fs.readFile(path.join(__dirname, 'fixtures', 'index_manufacturers.json'), 'utf8', (error, data) => {
if (error) {
addFileReadError('There was an error reading in the manufacturer index data.', error);
return;
}

manufacturersIndex = JSON.parse(data);
});
fs.readFile('fixtures/index_types.json', 'utf8', (error, data) => {
fs.readFile(path.join(__dirname, 'fixtures', 'index_types.json'), 'utf8', (error, data) => {
if (error) {
addFileReadError('There was an error reading in the category index data.', error);
return;
Expand Down Expand Up @@ -119,7 +120,7 @@ function renderSingleManufacturer(response, man) {
let fixtures = [];

for (let fix of manufacturersIndex[man]) {
const fixData = JSON.parse(fs.readFileSync(`fixtures/${man}/${fix}.json`, 'utf-8'));
const fixData = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', man, fix + '.json'), 'utf-8'));

fixtures.push({
path: man + '/' + fix,
Expand All @@ -136,7 +137,7 @@ function renderSingleManufacturer(response, man) {
}

function renderSingleFixture(response, man, fix) {
const fixData = JSON.parse(fs.readFileSync(`fixtures/${man}/${fix}.json`, 'utf-8'));
const fixData = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', man, fix + '.json'), 'utf-8'));

response.render('pages/single_fixture', {
title: `${manufacturers[man].name} ${fixData.name} - Open Fixture Library`,
Expand Down Expand Up @@ -164,6 +165,7 @@ function getMessages() {
}

function addFileReadError(text, error) {
console.error(text, error.toString());
messages.push({
type: 'error',
text: `${text}<br /><code>${error.toString()}</code>`
Expand Down