fastify / point-of-view

Template rendering plugin for Fastify
MIT License
341 stars 86 forks source link

Latest version of Eta no longer works #385

Closed gurgunday closed 1 year ago

gurgunday commented 1 year ago

Prerequisites

Fastify version

4

Plugin version

latest

Node.js version

20

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

Latest

Description

Eta no longer works (it had a major rewrite in v3, could be related)

Steps to Reproduce

const path = require("path");
const app = require("fastify")();

app.register(require("@fastify/view"), {
  engine: {
    eta: require("eta"),
  },
  root: path.join(__dirname, "view"),
});

app.get("/", function (req, rep) {
  rep.view("index.eta");
});

app.listen({
  port: 3000,
  host: "127.0.0.1",
});

GET request to / returns: {"statusCode":500,"error":"Internal Server Error","message":"engine.configure is not a function"}

Expected Behavior

No response

4e576rt8uh9ij9okp commented 1 year ago

I have the same issue here. I looked up and engine.configure actually exists in the code itself. https://github.com/fastify/point-of-view/blob/db34d0e63fa85ec8adc5a1e43dd64d1b6b710465/index.js#L672-L675

Prerequisites

 * [x]  I have written a descriptive issue title

 * [x]  I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.22.2

Plugin version

8.0.0

Node.js version

20.6.1

Operating system

Ubuntu Server LTS

Operating system version (i.e. 20.04, 11.3, 10)

22.04.3 LTS

Uzlopak commented 1 year ago

Yeah but if eta does not have .configure than...

4e576rt8uh9ij9okp commented 1 year ago

Yeah but if eta does not have .configure than...

So eta broke the compatibility?

Uzlopak commented 1 year ago

I dont think so. Looking at the unit test, eta is wrong initialized.

It should be done like this according the unit tests:

const { Eta } = require('eta')
const path = require("path");
const app = require("fastify")();

app.register(require("@fastify/view"), {
  engine: {
    eta: new Eta(),
  },
  root: path.join(__dirname, "view"),
});

app.get("/", function (req, rep) {
  rep.view("index.eta");
});

app.listen({
  port: 3000,
  host: "127.0.0.1",
});
gurgunday commented 1 year ago

Yeah, this was not the case in v1/2 if I'm not mistaken

After v3, it ought to be initialized like how @Uzlopak did

It works on my end, feel free to comment if the issue persists

4e576rt8uh9ij9okp commented 1 year ago

Now I see it too lol https://github.com/fastify/point-of-view/blob/db34d0e63fa85ec8adc5a1e43dd64d1b6b710465/test/test-eta.js#L17-L33