Add svelte as a view engine to swaf #33

Merged
ashpie merged 97 commits from svelte into develop 2021-11-09 19:31:22 +01:00
2 changed files with 10 additions and 23 deletions
Showing only changes of commit a7f421d2f8 - Show all commits

View File

@ -46,6 +46,16 @@ export default class FrontendToolsComponent extends ApplicationComponent {
next();
});
// Add request context locals
router.use((req, res, next) => {
res.locals.url = req.url;
res.locals.params = req.params;
res.locals.query = req.query;
res.locals.body = req.body;
next();
});
}
public async preCompileViews(watch: boolean): Promise<void> {

View File

@ -56,31 +56,8 @@ export default class NunjucksComponent extends ApplicationComponent {
});
}
public async init(_router: Router): Promise<void> {
this.use(NunjucksMiddleware);
}
public getEnvironment(): Environment {
if (!this.environment) throw new Error('Environment not initialized.');
return this.environment;
}
}
export class NunjucksMiddleware extends Middleware {
private env?: Environment;
protected async handle(req: Request, res: Response, next: NextFunction): Promise<void> {
this.env = this.app.as(NunjucksComponent).getEnvironment();
res.locals.url = req.url;
res.locals.params = req.params;
res.locals.query = req.query;
res.locals.body = req.body;
next();
}
public getEnvironment(): Environment {
if (!this.env) throw new Error('Environment not initialized.');
return this.env;
}
}