Skip to content

Commit

Permalink
Allow to run without a repository folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Mar 1, 2024
1 parent ec3e378 commit ab24522
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const morgan = require('morgan');
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const winston = require('winston');
const path = require('path');
const canvas = require('canvas');

const app = express();
Expand Down Expand Up @@ -47,7 +46,7 @@ app.use(bodyParser.json({ limit: '5mb' }));
global.ImageData = canvas.ImageData; // Required since PIXI 7.2.x and Canvas update, temporary workaround (?). Not required if PIXI peer dependency <= 7.1.

if (!process.env.TEMPLATE_REPOSITORY) {
process.env.TEMPLATE_REPOSITORY = path.join(__dirname, '../repository');
logger.warn("The environment variable `TEMPLATE_REPOSITORY` is not defined. Templates caching/storage will not be persistent.");
}

const swaggerOptions = {
Expand All @@ -68,6 +67,10 @@ const swaggerOptions = {
},
},
servers: [
{
url: "/",
description: "Current Server"
},
{
url: "http://localhost:4000/",
description: "Development Server"
Expand All @@ -88,7 +91,7 @@ const swaggerOptions = {

const specs = swaggerJsdoc(swaggerOptions);
app.use(
"/api-docs",
"/swagger",
swaggerUi.serve,
swaggerUi.setup(specs, { explorer: true })
);
Expand Down
3 changes: 2 additions & 1 deletion src/services/RepositoryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RepositoryService {
load() {
try {
if (this.folder !== undefined) {
this.logger.info("Loading template from repository folder `"+ this.folder +"`...");
this.templates = RepositoryService.getTemplates(this.folder);
} else {
this.templates = [];
Expand All @@ -58,7 +59,7 @@ class RepositoryService {
} else {
templateId = sanitize(templateId);
}
if (this.folder !== null) {
if (this.folder !== undefined) {
if (fs.existsSync(this.folder)) {
const fullfile = path.join(this.folder, templateId + '.json');
fs.writeFileSync(fullfile, JSON.stringify(template));
Expand Down
4 changes: 4 additions & 0 deletions tests/render.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const supertest = require('supertest');
const app = require('../src/app');
const path = require('path');
const RepositoryService = require('../src/services/RepositoryService');

describe('Render Endpoint', () => {
if (!process.env.TEMPLATE_REPOSITORY) {
process.env.TEMPLATE_REPOSITORY = path.join(__dirname, '../repository');
}
const templates = RepositoryService.getTemplates(process.env.TEMPLATE_REPOSITORY);
templates.forEach(tpl => {
it('POST /render/image should generate a png | ' + tpl.id, async () => {
Expand Down

0 comments on commit ab24522

Please sign in to comment.