question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

original app settings aren't inherited for subapps

See original GitHub issue

Is your feature request related to a problem? Please describe. I have setup a subapp with new App() and used it for a login page. I have also set up a few middlewares and the pug view engine in the parent app instance. However, it keeps logging:

(node:23948) UnhandledPromiseRejectionWarning: TypeError: this.engines[options.ext] is not a function

Describe the solution you’d like res.render in the sub app should render the page.

Describe alternatives you’ve considered I have tried setting the same engine property in the subapp and it works fine, which is annoying because I don’t want to copy the settings to each subapp.

Additional context Maybe you could add a { inherit: booelan } property to the app options upon constructing a new app instance? That way people can choose not to inherit those properties. By the way, this also applies to app.set(“views”, …) and not just the view engine.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
talentlessguycommented, Dec 11, 2020

@creepinson you can solve it using a simple function:

// engine.ts

import { renderFile } from 'eta'
import { App } from '@tinyhttp/app'

export const enginedApp = (app: App) => {
  app.engine('eta', renderFile)

  return app
}

// server.ts

const app = enginedApp()

const app2 = enginedApp()
1reaction
talentlessguycommented, Dec 10, 2020

Also, this could go in a different issue but since this is related to the subapp issue:

I keep getting 404’s on the subapp root page (“/admin/”) but on “/admin/login” it works and actually tries to render the page.

Example:

export const adminApiRouter = new App({});
adminApiRouter.engine("pug", (path, data, opts, cb) =>
    renderFile(path, { opts, ...data }, cb)
);
adminApiRouter.set("views", path.join(__dirname, "../views"));
adminApiRouter.post("/api/login", async (req, res) => {
    const session = await getSession(req, res);
    const existingPass = config.toObject().adminPassword;
    if (req.body.password === existingPass) {
        session.auth = true;
        return res.status(200).redirect("/admin");
    } else {
        session.auth = false;
        return res.redirect("/admin/login");
    }
});
adminApiRouter.get("/login", (req, res) => res.render("admin/auth/login.pug")); // actually works (but has the issues with the app engine as mentioned above)
adminApiRouter.get("/", async (req, res) => { // renders not found page for some reason...
    const session = await getSession(req, res);
    if (session.auth && session.auth === true)
        return res.status(403).render("content.pug", {
            header: "403 Forbidden",
            content: "You are not logged in.",
        });
    else
        return res.render("content.pug", {
            header: "Welcome",
            content: "Welcome, homelab administrator.",
        });
});

// main index.ts
app.use("/admin", adminApiRouter);

please put it in the separate issue because it’s not related to the original issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Settings set in app.defaultConfiguration is not inherited #1637
Re-setting these in all sub-apps is tedious. ... It seems that some settings are seen by child app and some aren't. trust proxy...
Read more >
Blocking web.config inheritance in a sub-application
NET Core authentication project I get the message... This package may not be fully compatible with your project. ...and it automatically rolls ...
Read more >
Applications - Django documentation
This example shows project-specific configuration classes located in a submodule called apps.py . This is a convention, not a requirement. AppConfig subclasses ...
Read more >
Configure Windows Authentication in ASP.NET Core
Because the section is added outside of the <location> node, the settings are inherited by any sub-apps to the current app.
Read more >
Scott Forsyth's Blog - ASP.NET files and inheritance
NET web.config inheritance. Understanding which ASP.NET files and folders are inherited through folders and applications makes development ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found