diff --git a/dc3/Dockerfile b/dc3/Dockerfile new file mode 100644 index 0000000..42e1ec2 --- /dev/null +++ b/dc3/Dockerfile @@ -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" ] + diff --git a/dc3/docker-compose.yml b/dc3/docker-compose.yml new file mode 100644 index 0000000..38e1e59 --- /dev/null +++ b/dc3/docker-compose.yml @@ -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' +... diff --git a/express/app.js b/express/app.js index f9a4051..f38b8d1 100644 --- a/express/app.js +++ b/express/app.js @@ -1,31 +1,9 @@ -const createError = require('http-errors'); const express = require('express'); const path = require('path'); -const cookieParser = require('cookie-parser'); -const logger = require('morgan'); - const app = express(); -app.use(logger('tiny')); app.use(express.json()); app.use(express.urlencoded({extended: false})); -app.use(cookieParser()); 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; diff --git a/express/bin/www b/express/bin/www index 37214fb..f45a161 100644 --- a/express/bin/www +++ b/express/bin/www @@ -5,7 +5,6 @@ */ const app = require('../app'); -const debug = require('debug')('express:server'); const http = require('http'); /** @@ -26,8 +25,6 @@ const server = http.createServer(app); */ server.listen(port); -server.on('error', onError); -server.on('listening', onListening); /** * Normalize a port into a number, string, or false. @@ -47,44 +44,4 @@ function normalizePort(val) { } 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); -} +} \ No newline at end of file diff --git a/express/package.json b/express/package.json index caa1e48..8a1493d 100644 --- a/express/package.json +++ b/express/package.json @@ -2,15 +2,11 @@ "name": "express", "author": "pnoker", "private": true, - "description": "IOT DC3 平台UI", + "description": "IOT DC3 平台 WEB", "scripts": { "start": "node ./bin/www" }, "dependencies": { - "cookie-parser": "~1.4.4", - "debug": "~2.6.9", - "express": "~4.16.1", - "http-errors": "~1.6.3", - "morgan": "~1.9.1" + "express": "~4.16.1" } }