Skip to content

Commit

Permalink
Removes the EJS dependency (#46)
Browse files Browse the repository at this point in the history
this low level dependency should that doesn't directly use EJS should not control which version it exposes. By having this here, it forces the dependents to use this version and making it overly complicated to update and fix security issues with ejs.
  • Loading branch information
acolchado authored Aug 3, 2022
1 parent 3eaf325 commit 439f614
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 167 deletions.
30 changes: 2 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ module.exports = function (BaseWebServer, path) {
// Add additional changes to the middleware by overriding the method
registerDefaultMiddleware() {
super.registerDefaultMiddleware();
this.registerEjsTemplates();
}

registerEjsTemplates() {
this.logSectionHeader('EJS Template Registration');

this.app.set('view engine', 'ejs');
this.app.set('views', path.join(__dirname, '../views'));
}
}

Expand All @@ -96,19 +88,6 @@ module.exports = function (BaseWebServer, path) {
};
```

#### `src/views/hello.ejs`

```html
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1><%= user %></h1>
</body>
</html>
```

#### `src/controllers/HelloController.js`

Files ending in `*Controller.js` are auto registered as controllers.
Expand All @@ -129,11 +108,7 @@ module.exports = function (BaseController) {
}

getHello(req, res) {
const model = {
user: req.query.user || 'John Doe'
};

res.render('hello', model);
res.send('hello');
}

}
Expand Down Expand Up @@ -184,7 +159,6 @@ List of external dependencies used and exposed by spur-web. They can be found at
| **cookieParser** | [cookie-parser](https://www.npmjs.org/package/cookie-parser) |
| **bodyParser** | [body-parser](https://www.npmjs.org/package/body-parser) |
| **expressWinston** | [express-winston](https://www.npmjs.org/package/express-winston) |
| **ejs** | [ejs](https://www.npmjs.org/package/ejs) |

### Local dependecies

Expand Down Expand Up @@ -244,4 +218,4 @@ $ npm test
[npm-install-size-image]: https://badgen.net/packagephobia/install/spur-web
[npm-install-size-url]: https://packagephobia.com/result?p=spur-web
[npm-url]: https://npmjs.org/package/spur-web
[npm-version-image]: https://badgen.net/npm/v/spur-web
[npm-version-image]: https://badgen.net/npm/v/spur-web
9 changes: 1 addition & 8 deletions example/src/runtime/WebServer.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
module.exports = function (BaseWebServer, path) {
module.exports = function (BaseWebServer) {
class WebServer extends BaseWebServer {

// Add additional changes to the middleware by overriding the method
registerDefaultMiddleware() {
super.registerDefaultMiddleware();
this.registerEjsTemplates();
}

registerEjsTemplates() {
this.logSectionHeader('EJS Template Registration');

this.app.set('view engine', 'ejs');
this.app.set('views', path.join(__dirname, '../views'));
}
}

// Assure there is just one instance
Expand Down
120 changes: 12 additions & 108 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"dependencies": {
"body-parser": "^1.20.0",
"cookie-parser": "^1.4.6",
"ejs": "^3.1.8",
"express": "^4.18.1",
"express-device": "^0.4.2",
"express-winston": "^2.6.0",
Expand Down
4 changes: 1 addition & 3 deletions src/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const methodOverride = require('method-override');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const expressWinston = require('express-winston');
const ejs = require('ejs');

module.exports = function injector() {
const ioc = spur.create('spur-web');
Expand All @@ -17,8 +16,7 @@ module.exports = function injector() {
methodOverride,
cookieParser,
bodyParser,
expressWinston,
ejs
expressWinston
});

ioc.registerFolders(__dirname, [
Expand Down
9 changes: 1 addition & 8 deletions test/fixtures/runtime/TestWebServer.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
module.exports = function (BaseWebServer, Logger, path) {
module.exports = function (BaseWebServer) {

class TestWebServer extends BaseWebServer {

registerDefaultMiddleware(){
super.registerDefaultMiddleware();
this.registerEjsTemplates();
}

registerEjsTemplates() {
Logger.log('EJS Template Registration');

this.app.set('view engine', 'ejs');
this.app.set('views', path.join(__dirname, '../views'));
}
}

return new TestWebServer();
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/views/renderView.ejs

This file was deleted.

3 changes: 1 addition & 2 deletions test/integration/ModuleIntegration_Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ describe('Integration', () => {

describe('base dependencies', () => {
it('base module dependencies are injectable', function () {
this.ioc.inject(function (express, expressDevice, methodOverride, cookieParser, bodyParser, expressWinston, ejs) {
this.ioc.inject(function (express, expressDevice, methodOverride, cookieParser, bodyParser, expressWinston) {
expect(express).to.exist;
expect(expressDevice).to.exist;
expect(methodOverride).to.exist;
expect(cookieParser).to.exist;
expect(bodyParser).to.exist;
expect(expressWinston).to.exist;
expect(ejs).to.exist;
});
});
});
Expand Down
8 changes: 0 additions & 8 deletions test/unit/middleware/PromiseMiddlewareSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ describe('PromiseMiddleware', function () {
expect(response.body).to.equal('jsonAsync success');
});
});

it('renderAsync - success', () => {
return base.getResponse('renderasync').promise().then((response) => {
expect(response.type).to.equal('text/html');
expect(response.text).to.contain('renderView from ejs: renderAsync success');
});
});

it('sendStatusAsync - success', () => {
return base.getResponse('sendstatusasync').promise().then((response) => {
expect(response.type).to.equal('text/plain');
Expand Down

0 comments on commit 439f614

Please sign in to comment.