Skip to content

Commit

Permalink
use docker
Browse files Browse the repository at this point in the history
  • Loading branch information
hassy55 committed Dec 10, 2021
1 parent 045f306 commit e5acc4a
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 90 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:16.13-buster-slim

WORKDIR /home/node/app
COPY lib lib
COPY package.json .
COPY gulpfile.js .
RUN npm install
RUN npm install -g http-server
RUN npm run build
RUN npm prune --production

CMD [ "npm", "start" ]
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.7"
services:
app:
build: .
volumes:
- .:/home/node/app
- /home/node/app/node_modules
- /home/node/app/lib/api
ports:
- "3000:3000"
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gulp.task("download", () => {
.pipe(decompress())
.pipe(convertEncoding({ from: "shift_jis", to: "utf-8" }))
.pipe(chmod(644))
.pipe(gulp.dest("api"));
.pipe(gulp.dest("lib/api"));
});

/**
Expand All @@ -28,11 +28,11 @@ gulp.task(
"v1",
gulp.series("download", () => {
return gulp
.src("api/KEN_ALL_ROME.CSV")
.src("lib/api/KEN_ALL_ROME.CSV")
.pipe(postal2json())
.pipe(v1())
.pipe(chmod(644))
.pipe(gulp.dest("api/v1"));
.pipe(gulp.dest("lib/api/v1"));
})
);

Expand All @@ -43,11 +43,11 @@ gulp.task(
"v1-jigyosyo",
gulp.series("download", () => {
return gulp
.src("api/JIGYOSYO.CSV")
.src("lib/api/JIGYOSYO.CSV")
.pipe(jigyosyo2json())
.pipe(v1())
.pipe(chmod(644))
.pipe(gulp.dest("api/v1"));
.pipe(gulp.dest("lib/api/v1"));
})
);

Expand Down
2 changes: 1 addition & 1 deletion example/index.html → lib/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h1>郵便番号 API</h1>
return;
}

var endpoint = 'https://madefor.github.io/postal-code-api/api/v1';
var endpoint = '/api/v1';
var code1 = $scope.code.replace(/^([0-9]{3}).*/, "$1");
var code2 = $scope.code.replace(/.*([0-9]{4})$/, "$1");

Expand Down
130 changes: 60 additions & 70 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "",
"scripts": {
"start": "http-server -c1 -o",
"start": "http-server lib/ -c1 -o --cors -p 3000",
"build": "gulp",
"test": "node tests/test.js"
},
Expand All @@ -17,5 +17,6 @@
"gulp-decompress": "^1.2.0",
"gulp-download": "0.0.1",
"http-server": "^0.9.0"
}
},
"dependencies": {}
}
37 changes: 25 additions & 12 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
const csv = require( 'comma-separated-values' );
const fs = require( 'fs' )
const path = require( 'path' )
const csv = require("comma-separated-values");
const fs = require("fs");
const path = require("path");

fs.readFile( 'api/KEN_ALL_ROME.CSV', 'utf8', ( err, data ) => {
fs.readFile("lib/api/KEN_ALL_ROME.CSV", "utf8", (err, data) => {
if (err) throw err;

const res = new csv( data, {
cast: [ 'String', 'String', 'String', 'String', 'String', 'String', 'String' ]
} ).parse();
const res = new csv(data, {
cast: [
"String",
"String",
"String",
"String",
"String",
"String",
"String",
],
}).parse();

for ( var i = 0; i < res.length; i++ ) {
const p = res[i][0].trim()
fs.statSync( path.join( 'api', 'v1',
p.replace( /^([0-9]{3}).*/, '$1' ),
p.replace( /.*([0-9]{4})$/, '$1' ) + '.json' ) )
for (var i = 0; i < res.length; i++) {
const p = res[i][0].trim();
fs.statSync(
path.join(
"api",
"v1",
p.replace(/^([0-9]{3}).*/, "$1"),
p.replace(/.*([0-9]{4})$/, "$1") + ".json"
)
);
}
});

0 comments on commit e5acc4a

Please sign in to comment.