pull/1/head
pnoker 6 years ago
parent c04255d98c
commit 4474093bbe

@ -0,0 +1,32 @@
#
# Copyright 2019 Pnoker. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
FROM node:12.14
MAINTAINER pnoker pnokers.icloud.com
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& mkdir -p /dc3-web
WORKDIR /dc3-web
ADD ./express ./
RUN npm install
EXPOSE 3000
CMD [ "node", "./bin/www" ]

@ -0,0 +1,22 @@
version: '3.7'
services:
web:
build:
context: ../
dockerfile: ./dc3/Dockerfile
image: pnoker/dc3-web:3.0
restart: always
ports:
- 3000:3000
container_name: dc3.web
hostname: dc3.web
networks:
dc3net:
aliases:
- dc3.web
networks:
dc3net:
driver: 'overlay'
...

@ -1,31 +1,9 @@
const createError = require('http-errors');
const express = require('express'); const express = require('express');
const path = require('path'); const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const app = express(); const app = express();
app.use(logger('tiny'));
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({extended: false})); app.use(express.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});
// error handler
app.use(function (err, req, res) {
// 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; module.exports = app;

@ -5,7 +5,6 @@
*/ */
const app = require('../app'); const app = require('../app');
const debug = require('debug')('express:server');
const http = require('http'); const http = require('http');
/** /**
@ -26,8 +25,6 @@ const server = http.createServer(app);
*/ */
server.listen(port); server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/** /**
* Normalize a port into a number, string, or false. * Normalize a port into a number, string, or false.
@ -47,44 +44,4 @@ function normalizePort(val) {
} }
return false; return false;
} }
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
const bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
const addr = server.address();
const bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}

@ -2,15 +2,11 @@
"name": "express", "name": "express",
"author": "pnoker", "author": "pnoker",
"private": true, "private": true,
"description": "IOT DC3 平台UI", "description": "IOT DC3 平台 WEB",
"scripts": { "scripts": {
"start": "node ./bin/www" "start": "node ./bin/www"
}, },
"dependencies": { "dependencies": {
"cookie-parser": "~1.4.4", "express": "~4.16.1"
"debug": "~2.6.9",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"morgan": "~1.9.1"
} }
} }

Loading…
Cancel
Save