Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gateway-selector
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gateway-selector
Commits
0791b2ba
Commit
0791b2ba
authored
Jul 27, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format
parent
cd7df123
Pipeline
#356
passed with stages
in 6 minutes and 19 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
+12
-3
package.json
package.json
+1
-1
server.ts
server.ts
+11
-2
No files found.
package.json
View file @
0791b2ba
...
...
@@ -19,7 +19,7 @@
},
"devDependencies"
:
{},
"scripts"
:
{
"build"
:
"./node_modules/.bin/tsc"
,
"build"
:
"./node_modules/.bin/tsc
&& rm -rf build/public && cp -rf public build
"
,
"start"
:
"node build/server.js"
},
"repository"
:
{
...
...
server.ts
View file @
0791b2ba
...
...
@@ -4,6 +4,7 @@ import { Selector } from "./lib/selector";
import
http
from
"
http
"
;
import
https
from
"
https
"
;
import
fs
from
"
fs
"
;
import
path
from
"
path
"
;
const
app
=
express
();
app
.
use
(
express
.
json
());
...
...
@@ -16,10 +17,12 @@ async function main() {
app
.
set
(
"
trust proxy
"
,
config
.
trustedProxies
);
app
.
get
(
"
/api/get
"
,
async
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
{
const
addr
=
req
.
ip
;
const
groups
=
await
selector
.
get
(
addr
);
res
.
json
({
ip
:
addr
,
groups
});
res
.
json
({
ip
:
addr
,
groups
});
});
app
.
post
(
"
/api/add
"
,
async
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
{
...
...
@@ -35,10 +38,16 @@ async function main() {
res
.
json
(
result
);
});
const
staticDir
=
path
.
join
(
__dirname
,
'
public
'
);
app
.
use
(
express
.
static
(
staticDir
));
app
.
get
(
'
/
'
,
(
req
:
express
.
Request
,
res
:
express
.
Response
)
=>
{
res
.
sendFile
(
'
index.html
'
,
{
root
:
staticDir
});
});
if
(
config
.
ssl
)
{
const
cert
=
await
fs
.
promises
.
readFile
(
config
.
ssl
.
cert
);
const
key
=
await
fs
.
promises
.
readFile
(
config
.
ssl
.
key
);
const
server
=
https
.
createServer
({
cert
,
key
},
app
);
const
server
=
https
.
createServer
({
cert
,
key
},
app
);
server
.
listen
(
config
.
port
,
config
.
address
);
}
else
{
const
server
=
http
.
createServer
(
app
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment