Commit 0791b2ba authored by nanahira's avatar nanahira

format

parent cd7df123
Pipeline #356 passed with stages
in 6 minutes and 19 seconds
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {
"build": "./node_modules/.bin/tsc", "build": "./node_modules/.bin/tsc && rm -rf build/public && cp -rf public build",
"start": "node build/server.js" "start": "node build/server.js"
}, },
"repository": { "repository": {
......
...@@ -4,6 +4,7 @@ import { Selector } from "./lib/selector"; ...@@ -4,6 +4,7 @@ import { Selector } from "./lib/selector";
import http from "http"; import http from "http";
import https from "https"; import https from "https";
import fs from "fs"; import fs from "fs";
import path from "path";
const app = express(); const app = express();
app.use(express.json()); app.use(express.json());
...@@ -16,10 +17,12 @@ async function main() { ...@@ -16,10 +17,12 @@ async function main() {
app.set("trust proxy", config.trustedProxies); app.set("trust proxy", config.trustedProxies);
app.get("/api/get", async (req: express.Request, res: express.Response) => { app.get("/api/get", async (req: express.Request, res: express.Response) => {
const addr = req.ip; const addr = req.ip;
const groups = await selector.get(addr); 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) => { app.post("/api/add", async (req: express.Request, res: express.Response) => {
...@@ -35,10 +38,16 @@ async function main() { ...@@ -35,10 +38,16 @@ async function main() {
res.json(result); 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) { if (config.ssl) {
const cert = await fs.promises.readFile(config.ssl.cert); const cert = await fs.promises.readFile(config.ssl.cert);
const key = await fs.promises.readFile(config.ssl.key); 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); server.listen(config.port, config.address);
} else { } else {
const server = http.createServer(app); const server = http.createServer(app);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment