Skip to content

Commit e523d52

Browse files
committed
initial
0 parents  commit e523d52

File tree

13 files changed

+355
-0
lines changed

13 files changed

+355
-0
lines changed

.dockerignore

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.idea
2+
*.iml
3+
docker
4+
5+
# Created by .ignore support plugin (hsz.mobi)
6+
### Node template
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# TypeScript v1 declaration files
46+
typings/
47+
48+
# Optional npm cache directory
49+
.npm
50+
51+
# Optional eslint cache
52+
.eslintcache
53+
54+
# Optional REPL history
55+
.node_repl_history
56+
57+
# Output of 'npm pack'
58+
*.tgz
59+
60+
# Yarn Integrity file
61+
.yarn-integrity
62+
63+
# dotenv environment variables file
64+
.env
65+
66+
# parcel-bundler cache (https://parceljs.org/)
67+
.cache
68+
69+
# next.js build output
70+
.next
71+
72+
# nuxt.js build output
73+
.nuxt
74+
75+
# vuepress build output
76+
.vuepress/dist
77+
78+
# Serverless directories
79+
.serverless

.gitignore

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.idea
2+
*.iml
3+
package-lock.json
4+
5+
# Created by .ignore support plugin (hsz.mobi)
6+
### Node template
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Runtime data
15+
pids
16+
*.pid
17+
*.seed
18+
*.pid.lock
19+
20+
# Directory for instrumented libs generated by jscoverage/JSCover
21+
lib-cov
22+
23+
# Coverage directory used by tools like istanbul
24+
coverage
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# TypeScript v1 declaration files
46+
typings/
47+
48+
# Optional npm cache directory
49+
.npm
50+
51+
# Optional eslint cache
52+
.eslintcache
53+
54+
# Optional REPL history
55+
.node_repl_history
56+
57+
# Output of 'npm pack'
58+
*.tgz
59+
60+
# Yarn Integrity file
61+
.yarn-integrity
62+
63+
# dotenv environment variables file
64+
.env
65+
66+
# parcel-bundler cache (https://parceljs.org/)
67+
.cache
68+
69+
# next.js build output
70+
.next
71+
72+
# nuxt.js build output
73+
.nuxt
74+
75+
# vuepress build output
76+
.vuepress/dist
77+
78+
# Serverless directories
79+
.serverless

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:carbon
2+
3+
RUN mkdir -p /usr/src/app
4+
WORKDIR /usr/src/app
5+
6+
7+
COPY package.json /usr/src/app/
8+
RUN npm install --production
9+
10+
COPY . /usr/src/app
11+
12+
13+
EXPOSE 3000
14+
15+
ARG profile
16+
17+
ENV NODE_PROFILE=${profile}
18+
19+
CMD npm run $NODE_PROFILE

app.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const createError = require('http-errors');
2+
const express = require('express');
3+
const logger = require('morgan');
4+
const errorHandler = require('./errors/handler');
5+
6+
const rootRouter = require('./routes/root');
7+
8+
const app = express();
9+
10+
11+
app.use(logger('dev'));
12+
app.use(express.json());
13+
14+
app.use('/', rootRouter);
15+
16+
// catch 404 and forward to error handler
17+
app.use(function (req, res, next) {
18+
next(createError(404));
19+
});
20+
21+
app.use(errorHandler);
22+
23+
module.exports = app;

bin/www

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

config/default.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

config/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var nconf = require('nconf');
2+
var path = require('path');
3+
4+
nconf.argv().env();
5+
6+
var environment = nconf.get('NODE_ENV') || 'default';
7+
8+
nconf.argv()
9+
.env()
10+
.file({file: path.join(__dirname, './' + environment.toLowerCase() + '.json')});
11+
12+
module.exports = new Proxy(nconf, {
13+
get: (target, p) => target.get(p),
14+
set: () => {
15+
} // do nothing
16+
});

docker-build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
PROFILE=${1:-default}
4+
echo "using profile ${PROFILE}"
5+
docker build --build-arg profile=${PROFILE} -t composer:${PROFILE} .

errors/BaseError.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = class BaseError extends Error {
2+
constructor(status, message) {
3+
super(message);
4+
this.status = status;
5+
}
6+
};

errors/ValidationError.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const BaseError = require('./BaseError');
2+
3+
module.exports = class ValidationError extends BaseError {
4+
constructor(message) {
5+
super(400, message);
6+
}
7+
};

0 commit comments

Comments
 (0)