Skip to content

Commit 4d3cdf7

Browse files
author
Tomáš Stankovič
committed
Server back to .js
1 parent 9392fa8 commit 4d3cdf7

8 files changed

Lines changed: 55 additions & 40 deletions

File tree

gulpfile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ gulp.task('build', function() {
139139
runSequence('clean', 'stylus', 'test', 'webpack', 'imagemin');
140140
});
141141

142+
/**
143+
* gulp release --version major|minor|patch
144+
* gulp release -v major|minor|patch
145+
*/
142146
gulp.task('release', function() {
143147
VERSION = args.v || args.version;
144148

@@ -152,7 +156,7 @@ gulp.task('release', function() {
152156
gulp.task('start-server', function() {
153157
nodemon({
154158
script: 'server/app.js',
155-
exec: 'babel-node',
159+
exec: 'node',
156160
watch: ['server/**/*.js']
157161
}).on('start');
158162

server/app.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/**
22
* Main app start point.
33
*/
4-
import express from 'express';
5-
const app = express();
4+
var express = require('express');
65

7-
import * as config from './config';
8-
import * as error from './lib/error_handler';
6+
var app = express();
7+
8+
var config = require('./config');
9+
var error = require('./lib/error_handler');
910

1011
config.appSetup(app);
1112
//config.dbConnect();
1213
error.setup(app);
1314

14-
app.listen(config.port, () => {
15+
app.listen(config.port, function() {
1516
console.log('Listening on port %d', config.port);
1617
});

server/config.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,30 @@
22
* Middleware config.
33
*/
44
var express = require('express'),
5-
bodyParser = require('body-parser'),
6-
compress = require('compression'),
7-
cookieParser = require('cookie-parser'),
8-
session = require('express-session'),
9-
favicon = require('serve-favicon'),
10-
flash = require('connect-flash'),
11-
methodOverride = require('method-override'),
12-
mongoose = require('mongoose'),
13-
path = require('path'),
14-
i18n = require('i18n'),
15-
router = require('./router'),
16-
pjson = require('../package.json');
5+
bodyParser = require('body-parser'),
6+
compress = require('compression'),
7+
cookieParser = require('cookie-parser'),
8+
session = require('express-session'),
9+
favicon = require('serve-favicon'),
10+
flash = require('connect-flash'),
11+
methodOverride = require('method-override'),
12+
mongoose = require('mongoose'),
13+
path = require('path'),
14+
i18n = require('i18n'),
15+
router = require('./router'),
16+
pjson = require('../package.json');
1717

18-
const DEV_ENV = 'DEVELOPMENT',
19-
APP_VER = pjson.version,
20-
DB_URL = process.env.DB_URL || 'db_url_here';
21-
22-
export const CURRENT_ENV = process.env.NODE_ENV || DEV_ENV;
23-
export const port = process.env.PORT || 8080;
18+
var DEV_ENV = 'DEVELOPMENT',
19+
CURRENT_ENV = process.env.NODE_ENV || DEV_ENV,
20+
APP_VER = pjson.version,
21+
port = process.env.PORT || 8080,
22+
DB_URL = 'db_url_here';
2423

2524
/**
2625
* Basic app setup.
2726
* @param {Object} app Express object
2827
*/
29-
export function appSetup(app) {
28+
var appSetup = function(app) {
3029
app.locals.CURRENT_ENV = CURRENT_ENV;
3130
app.locals.APP_VER = APP_VER;
3231
app.set('view engine', 'jade');
@@ -95,13 +94,13 @@ export function appSetup(app) {
9594
}));
9695
}
9796

98-
router(app);
97+
router.setup(app);
9998
};
10099

101100
/**
102101
* Database connection.
103102
*/
104-
export function dbConnect() {
103+
var dbConnect = function() {
105104
mongoose.connect(DB_URL, function(err) {
106105
if (err) {
107106
console.log('MongoDB: Connecting error : ' + err);
@@ -110,3 +109,10 @@ export function dbConnect() {
110109
}
111110
});
112111
};
112+
113+
module.exports = {
114+
CURRENT_ENV: CURRENT_ENV,
115+
port: port,
116+
dbConnect: dbConnect,
117+
appSetup: appSetup
118+
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
22
* Statics router.
33
*/
4-
import express from 'express';
5-
const router = express.Router();
4+
var express = require('express'),
5+
router = express.Router();
66

77
/**
88
* GET: Index
99
*/
10-
router.get('/', (req, res) => {
10+
router.get('/', function(req, res) {
1111
res.render('static/index');
1212
});
1313

14-
export default router;
14+
module.exports = router;

server/lib/error_handler.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/**
22
* Error handler.
33
*/
4-
const DEV_ENV = 'DEVELOPMENT';
5-
const CURRENT_ENV = process.env.NODE_ENV || DEV_ENV;
64

7-
export function setup(app) {
5+
var DEV_ENV = 'DEVELOPMENT',
6+
CURRENT_ENV = process.env.NODE_ENV || DEV_ENV;
7+
8+
var setup = function(app) {
89

910
app.use(function(req, res, next) {
1011
res.render('error', {
@@ -24,3 +25,5 @@ export function setup(app) {
2425
});
2526
});
2627
};
28+
29+
module.exports.setup = setup;

server/models/sampleModel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Sample model.
2+
* Sport model.
33
*/
4-
import mongoose as 'mongoose';
4+
var mongoose = require('mongoose');
55

66
var sampleModel = new mongoose.Schema({
77
title: {
@@ -10,4 +10,4 @@ var sampleModel = new mongoose.Schema({
1010
}
1111
});
1212

13-
export default mongoose.model('sample', userModel);
13+
module.exports = mongoose.model('sample', userModel);

server/router.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/**
22
* App router.
33
*/
4-
import staticController from './controllers/staticController';
4+
var setup = function(app) {
5+
var staticController = require('./controllers/staticController');
56

6-
export default (app) => {
77
app.use('/', staticController);
88
};
9+
10+
module.exports.setup = setup;

webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = {
1010
],
1111
test: /\.js?$/,
1212
query: {
13-
plugins: ['transform-runtime'],
1413
presets: ['es2015']
1514
}
1615
}]

0 commit comments

Comments
 (0)