initial import
This commit is contained in:
commit
bcbb3d4297
12
.editorConfig
Normal file
12
.editorConfig
Normal 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
18
.gitignore
vendored
Normal 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
1
.yarnrc.yml
Normal file
|
|
@ -0,0 +1 @@
|
|||
nodeLinker: node-modules
|
||||
8
Dockerfile
Normal file
8
Dockerfile
Normal 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
8
README.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
```
|
||||
npm install
|
||||
npm run start
|
||||
```
|
||||
|
||||
```
|
||||
open http://localhost:3000
|
||||
```
|
||||
13
docker-compose.yml
Normal file
13
docker-compose.yml
Normal 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
15
package.json
Normal 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
31
src/index.ts
Normal 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}`
|
||||
);
|
||||
}
|
||||
);
|
||||
Loading…
Reference in a new issue