Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated JS files to ES6 syntax #252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 83 additions & 51 deletions templates/js/app.js.ejs
Original file line number Diff line number Diff line change
@@ -1,51 +1,83 @@
<% if (view) { -%>
var createError = require('http-errors');
<% } -%>
var express = require('express');
var path = require('path');
<% Object.keys(modules).sort().forEach(function (variable) { -%>
var <%- variable %> = require('<%- modules[variable] %>');
<% }); -%>

<% Object.keys(localModules).sort().forEach(function (variable) { -%>
var <%- variable %> = require('<%- localModules[variable] %>');
<% }); -%>

var app = express();

<% if (view) { -%>
// view engine setup
<% if (view.render) { -%>
app.engine('<%- view.engine %>', <%- view.render %>);
<% } -%>
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', '<%- view.engine %>');

<% } -%>
<% uses.forEach(function (use) { -%>
app.use(<%- use %>);
<% }); -%>

<% mounts.forEach(function (mount) { -%>
app.use(<%= mount.path %>, <%- mount.code %>);
<% }); -%>

<% if (view) { -%>
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

<% } -%>
module.exports = app;
< %
if (view) {
- % >
const createError = require('http-errors'); <
%
} - % >
const express = require('express');
const path = require('path'); <
%
Object.keys(modules).sort().forEach(variable => {
- % >
const < % -variable % > = require('<%- modules[variable] %>'); <
%
}); - % >

<
%
Object.keys(localModules).sort().forEach(variable => {
- % >
const < % -variable % > = require('<%- localModules[variable] %>'); <
%
}); - % >

const app = express();

<
%
if (view) {
- % >
// view engine setup
<
%
if (view.render) {
- % >
app.engine('<%- view.engine %>', < % -view.render % > ); <
%
} - % >
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', '<%- view.engine %>');

<
%
} - % >
<
%
uses.forEach(use => {
- % >
app.use( < % -use % > ); <
%
}); - % >

<
%
mounts.forEach(mount => {
- % >
app.use( < %= mount.path % > , < % -mount.code % > ); <
%
}); - % >

<
%
if (view) {
- % >
// catch 404 and forward to error handler
app.use((req, res, next) => {
next(createError(404));
});

// error handler
app.use((err, req, res, next) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

<
%
} - % >
module.exports = app;
12 changes: 7 additions & 5 deletions templates/js/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var express = require('express');
var router = express.Router();
const express = require('express');
const router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
router.get('/', (req, res, next) => {
res.render('index', {
title: 'Express'
});
});

module.exports = router;
module.exports = router;
8 changes: 4 additions & 4 deletions templates/js/routes/users.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var express = require('express');
var router = express.Router();
const express = require('express');
const router = express.Router();

/* GET users listing. */
router.get('/', function(req, res, next) {
router.get('/', (req, res, next) => {
res.send('respond with a resource');
});

module.exports = router;
module.exports = router;