initial import

This commit is contained in:
Nicola Zambello 2023-07-07 08:15:37 +02:00
commit bcbb3d4297
Signed by: nzambello
GPG key ID: 56E4A92C2C1E50BA
9 changed files with 1555 additions and 0 deletions

12
.editorConfig Normal file
View file

@ -0,0 +1,12 @@
[*]
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
[{*.css,*.scss,*.less,*.overrides,*.variables}]
indent_size = 4
[{*.js,*.jsx,*.json,*.ts,*.tsx}]
indent_size = 2

18
.gitignore vendored Normal file
View file

@ -0,0 +1,18 @@
*.log
*.swp
.DS_Store
node_modules
.cache
dist
esm
storybook-static
tsconfig.tsbuildinfo
coverage
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

1
.yarnrc.yml Normal file
View file

@ -0,0 +1 @@
nodeLinker: node-modules

8
Dockerfile Normal file
View file

@ -0,0 +1,8 @@
# syntax=docker/dockerfile:1
FROM node:18-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["yarn", "start"]
EXPOSE 8787

8
README.md Normal file
View file

@ -0,0 +1,8 @@
```
npm install
npm run start
```
```
open http://localhost:3000
```

13
docker-compose.yml Normal file
View file

@ -0,0 +1,13 @@
version: '3.8'
services:
redirector:
image: nzambello/redirector
build:
context: .
dockerfile: Dockerfile
ports:
- "8787:8787"
environment:
- REDIRECT_URL=https://www.google.com
- PERMANENT=true

15
package.json Normal file
View file

@ -0,0 +1,15 @@
{
"name": "redirector",
"license": "Unlicense",
"main": "src/index.js",
"scripts": {
"start": "tsx src/index.ts"
},
"dependencies": {
"@hono/node-server": "^1.0.1",
"@types/node": "^20.4.0",
"hono": "^3.2.7",
"tiny-invariant": "^1.3.1",
"tsx": "^3.12.7"
}
}

31
src/index.ts Normal file
View file

@ -0,0 +1,31 @@
import { serve } from "@hono/node-server";
import { env } from "hono/adapter";
import { etag } from "hono/etag";
import { logger } from "hono/logger";
import { Hono } from "hono";
import invariant from "tiny-invariant";
const app = new Hono();
app.get("*", etag(), logger());
app.get("/", (c) => {
const { REDIRECT_URL, PERMANENT } = env(c);
invariant(REDIRECT_URL, "REDIRECT_URL environment variable is missing");
const isPermanentRedirect = PERMANENT && PERMANENT === "true";
return c.redirect(REDIRECT_URL, isPermanentRedirect ? 301 : 302);
});
serve(
{
fetch: app.fetch,
port: 8787,
},
(info) => {
console.log(
`Server is running on (${info.family}) http://${info.address}:${info.port}`
);
}
);

1449
yarn.lock Normal file

File diff suppressed because it is too large Load diff