Skip to content

Commit a31e48c

Browse files
authored
express: init (#271)
1 parent f82baea commit a31e48c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+7781
-22051
lines changed

.gitignore

-68
Original file line numberDiff line numberDiff line change
@@ -1,69 +1 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
8-
# Runtime data
9-
pids
10-
*.pid
11-
*.seed
12-
*.pid.lock
13-
14-
# Directory for instrumented libs generated by jscoverage/JSCover
15-
lib-cov
16-
17-
# Coverage directory used by tools like istanbul
18-
coverage
19-
20-
# nyc test coverage
21-
.nyc_output
22-
23-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24-
.grunt
25-
26-
# Bower dependency directory (https://bower.io/)
27-
bower_components
28-
29-
# node-waf configuration
30-
.lock-wscript
31-
32-
# Compiled binary addons (http://nodejs.org/api/addons.html)
33-
build/Release
34-
35-
# Dependency directories
361
node_modules/
37-
jspm_packages/
38-
39-
# Typescript v1 declaration files
40-
typings/
41-
42-
# Optional npm cache directory
43-
.npm
44-
45-
# Optional eslint cache
46-
.eslintcache
47-
48-
# Optional REPL history
49-
.node_repl_history
50-
51-
# Output of 'npm pack'
52-
*.tgz
53-
54-
# dotenv environment variables file
55-
.env
56-
57-
# gatsby files
58-
.cache/
59-
public
60-
61-
# Mac files
62-
.DS_Store
63-
64-
# Yarn
65-
yarn-error.log
66-
.pnp/
67-
.pnp.js
68-
# Yarn Integrity file
69-
.yarn-integrity

CNAME

-1
This file was deleted.

License.txt

-21
This file was deleted.

README.md

-22
This file was deleted.

app.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const createError = require('http-errors');
2+
const express = require('express');
3+
const path = require('path');
4+
const i18n = require('i18n');
5+
const hbs = require('express-hbs');
6+
const cookieParser = require('cookie-parser');
7+
const logger = require('morgan');
8+
const indexRouter = require('./routes/index');
9+
const langRouter = require('./routes/lang');
10+
const { directory, locales, metaData } = require('./locales');
11+
12+
const app = express();
13+
14+
i18n.configure({
15+
locales,
16+
objectNotation: true,
17+
defaultLocale: 'en_us',
18+
directory
19+
});
20+
21+
hbs.registerHelper('log', function(something) {
22+
console.log(something);
23+
return '' + something;
24+
});
25+
app.set('languagesMetaData', metaData);
26+
app.engine(
27+
'hbs',
28+
hbs.express4({
29+
layoutsDir: __dirname + '/views/layouts',
30+
defaultLayout: 'views/layouts/default',
31+
partialsDir: __dirname + '/views/partials',
32+
i18n
33+
})
34+
);
35+
app.set('views', path.join(__dirname, 'views'));
36+
app.set('view engine', 'hbs');
37+
app.use(i18n.init);
38+
app.use(logger('dev'));
39+
app.use(express.json());
40+
app.use(express.urlencoded({ extended: false }));
41+
app.use(cookieParser());
42+
app.use(express.static(path.join(__dirname, 'public')));
43+
app.use('/', indexRouter);
44+
app.use('/lang', langRouter);
45+
app.use(function(req, res, next) {
46+
next(createError(404));
47+
});
48+
app.use(function(err, req, res, next) {
49+
res.locals.message = err.message;
50+
res.locals.error = req.app.get('env') === 'development' ? err : {};
51+
res.status(err.status || 500);
52+
res.render('error');
53+
});
54+
55+
module.exports = app;

bin/www

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('vim-express:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}

gatsby-browser.js

-7
This file was deleted.

gatsby-config.js

-52
This file was deleted.

0 commit comments

Comments
 (0)