Skip to content

Commit ba66711

Browse files
committed
add code base
1 parent 6e9a41a commit ba66711

File tree

10 files changed

+118
-0
lines changed

10 files changed

+118
-0
lines changed

api/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+
# Create app directory
4+
WORKDIR /usr/src/app
5+
6+
# Install app dependencies
7+
# A wildcard is used to ensure both package.json AND package-lock.json are copied
8+
# where available (npm@5+)
9+
COPY package*.json ./
10+
11+
RUN npm install
12+
# If you are building your code for production
13+
# RUN npm install --only=production
14+
15+
# Bundle app source
16+
COPY . .
17+
18+
EXPOSE 3000
19+
CMD [ "npm", "start" ]

api/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var

api/configs/configs.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"env": "local",
3+
"appPort": 3000,
4+
"dbConfigs":
5+
{
6+
"user": "nero",
7+
"password": "nero",
8+
"host": "postgres",
9+
"port": 5432
10+
}
11+
}

api/configs/env.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var path = require('path');
2+
module.exports = function() {
3+
var envConfig;
4+
envConfig = require(path.join(__dirname, 'config.json'));
5+
return envConfig;
6+
}

api/dao/postgres.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var pg = require('pg');
2+
var dbConfigs = require('../configs/env')().dbConfigs;
3+
var pool = new pg.Pool(dbConfigs);
4+
5+
module.exports = {
6+
query: function(text, params, callback) {
7+
return pool.query(text, params, callback);
8+
},
9+
getClient: function(callback) {
10+
pool.connect(function(err, client, done) {
11+
callback(err, client, done);
12+
});
13+
}
14+
}

api/dao/uploadDao.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var client = require('.postgres.js');
2+
module.exports = {
3+
getDatebaseCurrentTime: function(callback) {
4+
5+
}
6+
}

api/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "nodejs_excel_import",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "node app.js"
9+
},
10+
"author": "Nero",
11+
"license": "MIT",
12+
"dependencies": {
13+
"body-passer": "~1.18.2",
14+
"debug": "~4.0.1",
15+
"expres": "~4.15.5",
16+
"morgan": "~1.9.1",
17+
"moment": "~2.18.1",
18+
"multer": "~1.4.0",
19+
"pg": "~7.4.3",
20+
"pg-native": "~3.0.0",
21+
"node-xlsx": "~0.12.1"
22+
23+
}
24+
}

api/routes/uploads.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var express = require('express');
2+
var router = express.Router();
3+
var multer = require('multer');
4+
var storage = multer.memoryStorage();
5+
var upload = multer({storage:storage});
6+
var xlsx = require('node-xlsx').default;
7+
var uploadDao = require('../dao/uploadDao');
8+
9+
router.post('/excel', upload.single('rawdata'), function(req, res, next) {
10+
var rawdata = req.file.buffer;
11+
if(typeof rawdata === 'undefined' || !rawdata) {
12+
return next({status: 404, message: 'Data is invalis'});
13+
}
14+
15+
var data = JSON.stringify(xlsx);
16+
return uploadDao.getDatebaseCurrentTime(function(err, result) {
17+
18+
})
19+
})

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "3"
2+
services:
3+
app:
4+
restart: "always"
5+
build: ./app
6+
ports:
7+
-"3000:3000"
8+
postgres:
9+
image: "postgres"
10+
environment:
11+
POSTGRES_PASSWORD: "mypass"
12+
POSTGRES_USER: "nero"
13+
POSTGRES_DB: "test"
14+
volumes:
15+
- ./postgres/db.sql:/docker-entrypoint-initdb.d/db.sql
16+
ports:
17+
- "5432:5432"
18+

postgres/db.sql

Whitespace-only changes.

0 commit comments

Comments
 (0)