Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e244ff2

Browse files
add app.json (#4)
1 parent e47cf96 commit e244ff2

File tree

8 files changed

+59
-16
lines changed

8 files changed

+59
-16
lines changed

‎.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ Dockerfile
55
README.md
66
node_modules
77
npm-debug.log
8-
build-for-run.sh
8+
build-for-run.sh
9+
dist

‎Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
FROM node:10
22

3-
LABEL version="0.0.2"
3+
LABEL version="0.0.3"
44

55
WORKDIR /usr/src/app
66

7+
COPY package*.json ./
8+
RUN npm install
9+
710
COPY . .
811

9-
RUN npm install
12+
RUN npm run build
1013

1114
VOLUME /usr/src/app
1215

13-
CMD [ "npm", "run", "start" ]
16+
EXPOSE 8080
17+
18+
CMD [ "npm", "run", "start" ]

‎README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ Create .env file. (see http.sample.env) and run:
1414

1515
```bash
1616
docker run -it --rm -p 443:443 -p 80:80 --env-file ./.env --name self-hosted-unpkg interactivetraining/self-hosted-unpkg
17-
```
17+
```
18+
19+
20+
21+
[![Run on Google Cloud](https://storage.googleapis.com/cloudrun/button.svg)](https://console.cloud.google.com/cloudshell/editor?shellonly=true&cloudshell_image=gcr.io/cloudrun/button&cloudshell_git_repo=https://github.com/InteractiveTraining/self-hosted-unpkg&cloudshell_git_branch=run-test)

‎app.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "my-self-hosted-unpkg",
3+
"env": {
4+
"NPM_REGISTRY": {
5+
"description": "You can provide your private repository here",
6+
"value": "https://registry.npmjs.com",
7+
"required": true
8+
},
9+
"NPM_TOKEN": {
10+
"description": "Only required if you want to allow access to your private packages",
11+
"value": " ",
12+
"required": false
13+
},
14+
"REDIS_HOST": {
15+
"description": "Redis is used to temporarily store packages to reduce load on the registry",
16+
"value": " ",
17+
"required": false
18+
},
19+
"REDIS_PORT": {
20+
"description": "Redis is used to temporarily store packages to reduce load on the registry",
21+
"value": "6379",
22+
"required": false
23+
},
24+
"REDIS_PASSWORD": {
25+
"description": "Redis is used to temporarily store packages to reduce load on the registry",
26+
"value": " ",
27+
"required": false
28+
},
29+
"CACHE_PREFIX": {
30+
"description": "Redis is used to temporarily store packages to reduce load on the registry",
31+
"value": "unpkg",
32+
"required": true
33+
}
34+
}
35+
}

‎src/cache.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as Redis from 'ioredis';
22
import {IPackageParams} from './interfaces';
33

4-
const redis = (process.env.REDIS_PORT && process.env.REDIS_HOST) ? new Redis({
5-
port: parseInt(process.env.REDIS_PORT),
6-
host: process.env.REDIS_HOST,
7-
password: process.env.REDIS_PASSWORD
8-
}) : undefined;
4+
const redis = (process.env.REDIS_PORT && process.env.REDIS_HOST && process.env.REDIS_PORT.trim().length > 1 && process.env.REDIS_HOST.trim().length > 1)
5+
? new Redis({
6+
port: parseInt(process.env.REDIS_PORT),
7+
host: process.env.REDIS_HOST,
8+
password: process.env.REDIS_PASSWORD
9+
}) : undefined;
910

1011
export class Cache {
1112
static get(key: string): Promise<string | null> {

‎src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {Cache} from './cache';
1010
export function getRegistryOptions(): RequestOptions {
1111
let options: RequestOptions = {};
1212

13-
if (process.env.NPM_TOKEN.trim() && process.env.NPM_TOKEN.trim().length > 0) {
13+
if (process.env.NPM_TOKEN && process.env.NPM_TOKEN.trim().length > 0) {
1414
options.headers = {authorization: `Bearer ${process.env.NPM_TOKEN.trim()}`};
1515
} else {
1616
options.auth = `${process.env.NPM_USER}:${process.env.NPM_PASSWORD}`;

‎src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as mime from 'mime-types';
2020

2121
app.get(['/:scope?/:package@:version/*', '/:scope?/:package/*'], async (req, res) => {
2222
try {
23-
let params: IPackageParams = req.params;
23+
let params: IPackageParams = (req.paramsasany);
2424

2525
// correct the params.package value when there isn't a scope or version provided
2626
if (!params.version && params.scope && !req.url.split('/')[1].includes('@')) {

‎tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
"sourceMap": false,
88
"emitDecoratorMetadata": true,
99
"experimentalDecorators": true,
10-
"outDir": "dist",
11-
"lib": [
12-
"esnext"
13-
]
10+
"outDir": "dist"
1411
},
1512
"include": [
1613
"src"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /