commit
01b0357f7d
22 changed files with 5412 additions and 0 deletions
@ -0,0 +1,23 @@ |
|||||||
|
**/.classpath |
||||||
|
**/.dockerignore |
||||||
|
**/.env |
||||||
|
**/.git |
||||||
|
**/.gitignore |
||||||
|
**/.project |
||||||
|
**/.settings |
||||||
|
**/.toolstarget |
||||||
|
**/.vs |
||||||
|
**/.vscode |
||||||
|
**/*.*proj.user |
||||||
|
**/*.dbmdl |
||||||
|
**/*.jfm |
||||||
|
**/azds.yaml |
||||||
|
**/charts |
||||||
|
**/docker-compose* |
||||||
|
**/Dockerfile* |
||||||
|
**/node_modules |
||||||
|
**/npm-debug.log |
||||||
|
**/obj |
||||||
|
**/secrets.dev.yaml |
||||||
|
**/values.dev.yaml |
||||||
|
README.md |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
{ |
||||||
|
"configurations": [ |
||||||
|
{ |
||||||
|
"name": "Docker Node.js Launch and Attach", |
||||||
|
"type": "docker", |
||||||
|
"request": "launch", |
||||||
|
"preLaunchTask": "docker-run: debug", |
||||||
|
"platform": "node" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
||||||
@ -0,0 +1,37 @@ |
|||||||
|
{ |
||||||
|
"tasks": [ |
||||||
|
{ |
||||||
|
"type": "docker-build", |
||||||
|
"label": "docker-build", |
||||||
|
"platform": "node", |
||||||
|
"dockerBuild": { |
||||||
|
"dockerfile": "${workspaceFolder}/Dockerfile", |
||||||
|
"context": "${workspaceFolder}" |
||||||
|
} |
||||||
|
}, |
||||||
|
{ |
||||||
|
"type": "docker-run", |
||||||
|
"label": "docker-run: release", |
||||||
|
"dependsOn": [ |
||||||
|
"docker-build" |
||||||
|
], |
||||||
|
"platform": "node" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"type": "docker-run", |
||||||
|
"label": "docker-run: debug", |
||||||
|
"dependsOn": [ |
||||||
|
"docker-build" |
||||||
|
], |
||||||
|
"dockerRun": { |
||||||
|
"env": { |
||||||
|
"DEBUG": "*", |
||||||
|
"NODE_ENV": "development" |
||||||
|
} |
||||||
|
}, |
||||||
|
"node": { |
||||||
|
"enableDebugging": true |
||||||
|
} |
||||||
|
} |
||||||
|
] |
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
FROM node:current-alpine AS builder |
||||||
|
WORKDIR /usr/src/app |
||||||
|
COPY /package.json /app/ |
||||||
|
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"] |
||||||
|
RUN apk add --no-cache git |
||||||
|
RUN npm install |
||||||
|
COPY . . |
||||||
@ -0,0 +1,4 @@ |
|||||||
|
following instructions from: |
||||||
|
https://www.freecodecamp.org/news/how-to-enable-es6-and-beyond-syntax-with-node-and-express-68d3e11fe1ab/ |
||||||
|
|
||||||
|
Can be used as a template for ES6 NodeJS projects. |
||||||
@ -0,0 +1,46 @@ |
|||||||
|
"use strict"; |
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", { |
||||||
|
value: true |
||||||
|
}); |
||||||
|
exports["default"] = void 0; |
||||||
|
|
||||||
|
var _express = _interopRequireDefault(require("express")); |
||||||
|
|
||||||
|
var _path = _interopRequireDefault(require("path")); |
||||||
|
|
||||||
|
var _cookieParser = _interopRequireDefault(require("cookie-parser")); |
||||||
|
|
||||||
|
var _morgan = _interopRequireDefault(require("morgan")); |
||||||
|
|
||||||
|
var _index = _interopRequireDefault(require("./routes/index")); |
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
||||||
|
|
||||||
|
// var express = require('express');
|
||||||
|
// var path = require('path');
|
||||||
|
// var cookieParser = require('cookie-parser');
|
||||||
|
// var logger = require('morgan');
|
||||||
|
// var indexRouter = require('./routes/index');
|
||||||
|
// var usersRouter = require('./routes/users');
|
||||||
|
// var app = express();
|
||||||
|
// app.use(logger('dev'));
|
||||||
|
// app.use(express.json());
|
||||||
|
// app.use(express.urlencoded({ extended: false }));
|
||||||
|
// app.use(cookieParser());
|
||||||
|
// app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
// app.use('/', indexRouter);
|
||||||
|
// app.use('/users', usersRouter);
|
||||||
|
// module.exports = app;
|
||||||
|
// app.js
|
||||||
|
var app = (0, _express["default"])(); |
||||||
|
app.use((0, _morgan["default"])('dev')); |
||||||
|
app.use(_express["default"].json()); |
||||||
|
app.use(_express["default"].urlencoded({ |
||||||
|
extended: false |
||||||
|
})); |
||||||
|
app.use((0, _cookieParser["default"])()); |
||||||
|
app.use(_express["default"]["static"](_path["default"].join(__dirname, '../public'))); |
||||||
|
app.use('/', _index["default"]); |
||||||
|
var _default = app; |
||||||
|
exports["default"] = _default; |
||||||
@ -0,0 +1,93 @@ |
|||||||
|
"use strict"; |
||||||
|
|
||||||
|
var _app = _interopRequireDefault(require("../app")); |
||||||
|
|
||||||
|
var _debug = _interopRequireDefault(require("debug")); |
||||||
|
|
||||||
|
var _http = _interopRequireDefault(require("http")); |
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
||||||
|
|
||||||
|
// bin/www.js
|
||||||
|
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
*/ |
||||||
|
var debug = (0, _debug["default"])('your-project-name:server'); |
||||||
|
/** |
||||||
|
* Get port from environment and store in Express. |
||||||
|
*/ |
||||||
|
|
||||||
|
var port = normalizePort(process.env.PORT || '3000'); |
||||||
|
|
||||||
|
_app["default"].set('port', port); |
||||||
|
/** |
||||||
|
* Create HTTP server. |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
var server = _http["default"].createServer(_app["default"]); |
||||||
|
/** |
||||||
|
* Listen on provided port, on all network interfaces. |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
server.listen(port); |
||||||
|
server.on('error', onError); |
||||||
|
server.on('listening', onListening); |
||||||
|
/** |
||||||
|
* Normalize a port into a number, string, or false. |
||||||
|
*/ |
||||||
|
|
||||||
|
function normalizePort(val) { |
||||||
|
var port = parseInt(val, 10); |
||||||
|
|
||||||
|
if (isNaN(port)) { |
||||||
|
// named pipe
|
||||||
|
return val; |
||||||
|
} |
||||||
|
|
||||||
|
if (port >= 0) { |
||||||
|
// port number
|
||||||
|
return port; |
||||||
|
} |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
/** |
||||||
|
* Event listener for HTTP server "error" event. |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
function onError(error) { |
||||||
|
if (error.syscall !== 'listen') { |
||||||
|
throw error; |
||||||
|
} |
||||||
|
|
||||||
|
var 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() { |
||||||
|
var addr = server.address(); |
||||||
|
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; |
||||||
|
debug('Listening on ' + bind); |
||||||
|
} |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
"use strict"; |
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", { |
||||||
|
value: true |
||||||
|
}); |
||||||
|
exports["default"] = void 0; |
||||||
|
|
||||||
|
var _express = _interopRequireDefault(require("express")); |
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
||||||
|
|
||||||
|
// var express = require('express');
|
||||||
|
// var router = express.Router();
|
||||||
|
// /* GET home page. */
|
||||||
|
// router.get('/', function(req, res, next) {
|
||||||
|
// res.render('index', { title: 'Express' });
|
||||||
|
// });
|
||||||
|
// module.exports = router;
|
||||||
|
// routes/index.js
|
||||||
|
var router = _express["default"].Router(); |
||||||
|
/* GET home page. */ |
||||||
|
|
||||||
|
|
||||||
|
router.get('/', function (req, res, next) { |
||||||
|
res.render('index', { |
||||||
|
title: 'Express' |
||||||
|
}); |
||||||
|
}); |
||||||
|
var _default = router; |
||||||
|
exports["default"] = _default; |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
version: "3.7" |
||||||
|
services: |
||||||
|
mongodb: |
||||||
|
image: mongo:latest |
||||||
|
container_name: mongodb |
||||||
|
volumes: |
||||||
|
- ./mongo_data:/data/db |
||||||
|
environment: |
||||||
|
- MONGO_INITDB_DATABASE=forms |
||||||
|
- MONGO_INITDB_ROOT_USERNAME=mongodbUser |
||||||
|
- MONGO_INITDB_ROOT_PASSWORD=mongodbPass |
||||||
|
ports: |
||||||
|
- "27017:27017" |
||||||
|
|
||||||
|
mongo-express: |
||||||
|
container_name: mongo-express |
||||||
|
depends_on: |
||||||
|
- mongodb |
||||||
|
image: mongo-express:latest |
||||||
|
environment: |
||||||
|
- ME_CONFIG_MONGODB_SERVER=mongodb |
||||||
|
- ME_CONFIG_MONGODB_PORT=27017 |
||||||
|
- ME_CONFIG_MONGODB_ADMINUSERNAME=mongodbUser |
||||||
|
- ME_CONFIG_MONGODB_ADMINPASSWORD=mongodbPass |
||||||
|
- ME_CONFIG_BASICAUTH_USERNAME=expressUser |
||||||
|
- ME_CONFIG_BASICAUTH_PASSWORD=expressPass |
||||||
|
- ME_CONFIG_MONGODB_ENABLE_ADMIN=true |
||||||
|
- ME_CONFIG_OPTIONS_EDITORTHEME=default |
||||||
|
ports: |
||||||
|
- "8081:8081" |
||||||
|
|
||||||
|
node: |
||||||
|
depends_on: |
||||||
|
- mongodb |
||||||
|
image: avaliacao-imovel-rural/air-backend |
||||||
|
container_name: air-backend |
||||||
|
build: |
||||||
|
context: . |
||||||
|
args: |
||||||
|
- HTTP_PROXY=http://192.168.128.1:3128 |
||||||
|
- HTTPS_PROXY=http://192.168.128.1:3128 |
||||||
|
- http_proxy=http://192.168.128.1:3128 |
||||||
|
- https_proxy=http://192.168.128.1:3128 |
||||||
|
ports: |
||||||
|
- "3001:3001" |
||||||
|
env_file: |
||||||
|
- .env |
||||||
|
environment: |
||||||
|
- NODEJS_HOST=0.0.0.0 |
||||||
|
- NODEJS_PORT=3001 |
||||||
|
- MONGO_DB_HOST=mongodb |
||||||
|
- MONGO_DB_PORT=27017 |
||||||
|
- MONGO_DB_URL=mongodb://mongodb:27017/analise-agro?authSource=admin |
||||||
|
- MONGO_DB_USER=mongodbUser |
||||||
|
- MONGO_DB_PWD=mongodbPass |
||||||
|
|
||||||
|
networks: |
||||||
|
default: |
||||||
|
ipam: |
||||||
|
driver: default |
||||||
|
config: |
||||||
|
- subnet: 172.17.1.0/24 |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
version: '2.1' |
||||||
|
|
||||||
|
services: |
||||||
|
es6-nodejs: |
||||||
|
image: es6-nodejs |
||||||
|
container_name: es6-nodejs |
||||||
|
build: . |
||||||
|
environment: |
||||||
|
NODE_ENV: development |
||||||
|
ports: |
||||||
|
- 3001:3001 |
||||||
|
- 9229:9229 |
||||||
|
## set your startup file here |
||||||
|
command: node --inspect=0.0.0.0:9229 index.js |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
version: '3.7' |
||||||
|
|
||||||
|
services: |
||||||
|
es6-nodejs: |
||||||
|
image: es6-nodejs |
||||||
|
container_name: es6-nodejs |
||||||
|
build: . |
||||||
|
ports: |
||||||
|
- 3001:3001 |
||||||
|
environment: |
||||||
|
- PORT=3001 |
||||||
|
command: ["npm","run","dev"] |
||||||
@ -0,0 +1,5 @@ |
|||||||
|
{ |
||||||
|
"exec": "npm run dev", |
||||||
|
"watch": ["src/*", "public/*"], |
||||||
|
"ext": "js, html, css, json" |
||||||
|
} |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
{ |
||||||
|
"name": "es6-nodejs", |
||||||
|
"version": "0.0.0", |
||||||
|
"private": true, |
||||||
|
"scripts": { |
||||||
|
"start": "npm run prod", |
||||||
|
"server": "babel-node ./src/server.js", |
||||||
|
"server:prod": "node ./dist/server.js", |
||||||
|
"dev": "NODE_ENV=development npm-run-all server", |
||||||
|
"clean": "rimraf dist", |
||||||
|
"build": "babel ./src --out-dir dist", |
||||||
|
"prod": "NODE_ENV=production npm-run-all clean build server:prod", |
||||||
|
"watch": "nodemon" |
||||||
|
}, |
||||||
|
"dependencies": { |
||||||
|
"cookie-parser": "~1.4.4", |
||||||
|
"debug": "~2.6.9", |
||||||
|
"express": "~4.16.1", |
||||||
|
"morgan": "~1.9.1", |
||||||
|
"npm-run-all": "^4.1.5", |
||||||
|
"rimraf": "^3.0.0", |
||||||
|
"cors": "^2.8.5" |
||||||
|
}, |
||||||
|
"devDependencies": { |
||||||
|
"@babel/cli": "^7.8.3", |
||||||
|
"@babel/core": "^7.8.3", |
||||||
|
"@babel/node": "^7.8.3", |
||||||
|
"@babel/preset-env": "^7.8.3", |
||||||
|
"nodemon": "^2.0.2" |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
<html> |
||||||
|
|
||||||
|
<head> |
||||||
|
<title>Express</title> |
||||||
|
<link rel="stylesheet" href="/stylesheets/style.css"> |
||||||
|
</head> |
||||||
|
|
||||||
|
<body> |
||||||
|
<h1>Express</h1> |
||||||
|
<p>Welcome to Express</p> |
||||||
|
</body> |
||||||
|
|
||||||
|
</html> |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
body { |
||||||
|
padding: 50px; |
||||||
|
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; |
||||||
|
} |
||||||
|
|
||||||
|
a { |
||||||
|
color: #00B7FF; |
||||||
|
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
// app.js
|
||||||
|
|
||||||
|
import express from 'express'; |
||||||
|
import path from 'path'; |
||||||
|
import cookieParser from 'cookie-parser'; |
||||||
|
import logger from 'morgan'; |
||||||
|
import indexRouter from './routes/index'; |
||||||
|
const app = express(); |
||||||
|
app.use(logger('dev')); |
||||||
|
app.use(express.json()); |
||||||
|
app.use(express.urlencoded({ extended: false })); |
||||||
|
app.use(cookieParser()); |
||||||
|
app.use(express.static(path.join(__dirname, '../public'))); |
||||||
|
app.use('/', indexRouter); |
||||||
|
export default app; |
||||||
@ -0,0 +1,89 @@ |
|||||||
|
// bin/www.js
|
||||||
|
/** |
||||||
|
* Module dependencies. |
||||||
|
*/ |
||||||
|
import app from '../app'; |
||||||
|
import debugLib from 'debug'; |
||||||
|
import http from 'http'; |
||||||
|
const debug = debugLib('es6-nodejs:server'); |
||||||
|
|
||||||
|
/** |
||||||
|
* Get port from environment and store in Express. |
||||||
|
*/ |
||||||
|
|
||||||
|
var port = normalizePort(process.env.PORT || '3000'); |
||||||
|
app.set('port', port); |
||||||
|
|
||||||
|
/** |
||||||
|
* Create HTTP server. |
||||||
|
*/ |
||||||
|
|
||||||
|
var server = http.createServer(app); |
||||||
|
|
||||||
|
/** |
||||||
|
* Listen on provided port, on all network interfaces. |
||||||
|
*/ |
||||||
|
|
||||||
|
server.listen(port); |
||||||
|
server.on('error', onError); |
||||||
|
server.on('listening', onListening); |
||||||
|
|
||||||
|
/** |
||||||
|
* Normalize a port into a number, string, or false. |
||||||
|
*/ |
||||||
|
|
||||||
|
function normalizePort(val) { |
||||||
|
var port = parseInt(val, 10); |
||||||
|
|
||||||
|
if (isNaN(port)) { |
||||||
|
// named pipe
|
||||||
|
return val; |
||||||
|
} |
||||||
|
|
||||||
|
if (port >= 0) { |
||||||
|
// port number
|
||||||
|
return port; |
||||||
|
} |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Event listener for HTTP server "error" event. |
||||||
|
*/ |
||||||
|
|
||||||
|
function onError(error) { |
||||||
|
if (error.syscall !== 'listen') { |
||||||
|
throw error; |
||||||
|
} |
||||||
|
|
||||||
|
var 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() { |
||||||
|
var addr = server.address(); |
||||||
|
var bind = typeof addr === 'string' |
||||||
|
? 'pipe ' + addr |
||||||
|
: 'port ' + addr.port; |
||||||
|
debug('Listening on ' + bind); |
||||||
|
} |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
// routes/index.js
|
||||||
|
import express from 'express'; |
||||||
|
var router = express.Router(); |
||||||
|
/* GET home page. */ |
||||||
|
router.get('/', function(req, res, next) { |
||||||
|
res.render('index', { title: 'Express' }); |
||||||
|
}); |
||||||
|
export default router; |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
import express from 'express'; |
||||||
|
import bodyParser from 'body-parser'; |
||||||
|
import cors from 'cors'; |
||||||
|
|
||||||
|
const app = express(); |
||||||
|
const PORT = 4000; |
||||||
|
|
||||||
|
app.use(cors()); |
||||||
|
app.use(bodyParser.json()); |
||||||
|
|
||||||
|
app.listen(PORT, function() { |
||||||
|
console.log("Server is running on Port: " + PORT); |
||||||
|
}); |
||||||
Loading…
Reference in new issue