Express: add custom bind address setting
This commit is contained in:
parent
9f31e5cbe9
commit
dfee2645e1
@ -7,6 +7,7 @@ module.exports = {
|
|||||||
db_log_level: "ERROR",
|
db_log_level: "ERROR",
|
||||||
base_url: "http://localhost:4899",
|
base_url: "http://localhost:4899",
|
||||||
public_websocket_url: "ws://localhost:4899",
|
public_websocket_url: "ws://localhost:4899",
|
||||||
|
listen_addr: '127.0.0.1',
|
||||||
port: 4899,
|
port: 4899,
|
||||||
gitlab_webhook_token: 'default',
|
gitlab_webhook_token: 'default',
|
||||||
mysql: {
|
mysql: {
|
||||||
|
@ -5,18 +5,20 @@ import {Server} from "http";
|
|||||||
import compression from "compression";
|
import compression from "compression";
|
||||||
|
|
||||||
export default class ExpressAppComponent extends ApplicationComponent<void> {
|
export default class ExpressAppComponent extends ApplicationComponent<void> {
|
||||||
|
private readonly addr: string;
|
||||||
private readonly port: number;
|
private readonly port: number;
|
||||||
private server?: Server;
|
private server?: Server;
|
||||||
private expressApp?: Express;
|
private expressApp?: Express;
|
||||||
|
|
||||||
constructor(port: number) {
|
public constructor(addr: string, port: number) {
|
||||||
super();
|
super();
|
||||||
|
this.addr = addr;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start(app: Express): Promise<void> {
|
public async start(app: Express): Promise<void> {
|
||||||
this.server = app.listen(this.port, 'localhost', () => {
|
this.server = app.listen(this.port, this.addr, () => {
|
||||||
Logger.info(`Web server running on localhost:${this.port}.`);
|
Logger.info(`Web server running on ${this.addr}:${this.port}.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Proxy
|
// Proxy
|
||||||
|
@ -4,7 +4,7 @@ import CsrfProtectionComponent from "../src/components/CsrfProtectionComponent";
|
|||||||
import supertest from "supertest";
|
import supertest from "supertest";
|
||||||
|
|
||||||
let app: TestApp;
|
let app: TestApp;
|
||||||
useApp(port => {
|
useApp((addr, port) => {
|
||||||
return app = new class extends TestApp {
|
return app = new class extends TestApp {
|
||||||
protected async init(): Promise<void> {
|
protected async init(): Promise<void> {
|
||||||
this.use(new class extends Controller {
|
this.use(new class extends Controller {
|
||||||
@ -29,7 +29,7 @@ useApp(port => {
|
|||||||
super.registerComponents();
|
super.registerComponents();
|
||||||
this.use(new CsrfProtectionComponent());
|
this.use(new CsrfProtectionComponent());
|
||||||
}
|
}
|
||||||
}(port);
|
}(addr, port);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Test CSRF protection', () => {
|
describe('Test CSRF protection', () => {
|
||||||
|
10
test/_app.ts
10
test/_app.ts
@ -18,12 +18,12 @@ import RedirectBackComponent from "../src/components/RedirectBackComponent";
|
|||||||
import ServeStaticDirectoryComponent from "../src/components/ServeStaticDirectoryComponent";
|
import ServeStaticDirectoryComponent from "../src/components/ServeStaticDirectoryComponent";
|
||||||
import {Express} from "express";
|
import {Express} from "express";
|
||||||
|
|
||||||
export default function useApp(appSupplier?: (port: number) => TestApp) {
|
export default function useApp(appSupplier?: (addr: string, port: number) => TestApp) {
|
||||||
let app: Application;
|
let app: Application;
|
||||||
|
|
||||||
beforeAll(async (done) => {
|
beforeAll(async (done) => {
|
||||||
await setupMailServer();
|
await setupMailServer();
|
||||||
app = appSupplier ? appSupplier(8966) : new TestApp(8966);
|
app = appSupplier ? appSupplier('127.0.0.1', 8966) : new TestApp('127.0.0.1', 8966);
|
||||||
|
|
||||||
await app.start();
|
await app.start();
|
||||||
done();
|
done();
|
||||||
@ -37,11 +37,13 @@ export default function useApp(appSupplier?: (port: number) => TestApp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TestApp extends Application {
|
export class TestApp extends Application {
|
||||||
|
private readonly addr: string;
|
||||||
private readonly port: number;
|
private readonly port: number;
|
||||||
private expressAppComponent?: ExpressAppComponent;
|
private expressAppComponent?: ExpressAppComponent;
|
||||||
|
|
||||||
constructor(port: number) {
|
constructor(addr: string, port: number) {
|
||||||
super(require('../package.json').version, true);
|
super(require('../package.json').version, true);
|
||||||
|
this.addr = addr;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +58,7 @@ export class TestApp extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected registerComponents() {
|
protected registerComponents() {
|
||||||
this.expressAppComponent = new ExpressAppComponent(this.port);
|
this.expressAppComponent = new ExpressAppComponent(this.addr, this.port);
|
||||||
const redisComponent = new RedisComponent();
|
const redisComponent = new RedisComponent();
|
||||||
const mysqlComponent = new MysqlComponent();
|
const mysqlComponent = new MysqlComponent();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user