General work on API
This commit is contained in:
parent
13eb680272
commit
442879e80a
@ -2,3 +2,7 @@ MONGO_URL=mongodb://localhost/fosscord
|
|||||||
PORT=3001
|
PORT=3001
|
||||||
PRODUCTION=TRUE
|
PRODUCTION=TRUE
|
||||||
THREADS=# automatically use all available cores, only available if production = true
|
THREADS=# automatically use all available cores, only available if production = true
|
||||||
|
#LOG_REQUESTS=
|
||||||
|
# only log 200 and 204: LOG_REQUESTS=200 204
|
||||||
|
# log everything except 200 and 204: LOG_REQUESTS=-200 204
|
||||||
|
# log all requests: LOG_REQUESTS=-
|
2180
api/package-lock.json
generated
2180
api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -84,6 +84,7 @@
|
|||||||
"missing-native-js-functions": "^1.2.18",
|
"missing-native-js-functions": "^1.2.18",
|
||||||
"morgan": "^1.10.0",
|
"morgan": "^1.10.0",
|
||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
|
"nanocolors": "^0.2.13",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"patch-package": "^6.4.7",
|
"patch-package": "^6.4.7",
|
||||||
"proxy-agent": "^5.0.0",
|
"proxy-agent": "^5.0.0",
|
||||||
|
@ -26,5 +26,6 @@ DROP TABLE webhooks;
|
|||||||
DROP TABLE channels;
|
DROP TABLE channels;
|
||||||
DROP TABLE members;
|
DROP TABLE members;
|
||||||
DROP TABLE guilds;
|
DROP TABLE guilds;
|
||||||
|
DROP TABLE client_relase;
|
||||||
-- DROP TABLE users;
|
-- DROP TABLE users;
|
||||||
-- DROP TABLE config;
|
-- DROP TABLE config;
|
@ -12,6 +12,7 @@ import { initTranslation } from "./middlewares/Translation";
|
|||||||
import morgan from "morgan";
|
import morgan from "morgan";
|
||||||
import { initInstance } from "./util/Instance";
|
import { initInstance } from "./util/Instance";
|
||||||
import { registerRoutes } from "@fosscord/util";
|
import { registerRoutes } from "@fosscord/util";
|
||||||
|
import { red } from "nanocolors"
|
||||||
|
|
||||||
export interface FosscordServerOptions extends ServerOptions {}
|
export interface FosscordServerOptions extends ServerOptions {}
|
||||||
|
|
||||||
@ -38,17 +39,6 @@ export class FosscordServer extends Server {
|
|||||||
await initEvent();
|
await initEvent();
|
||||||
await initInstance();
|
await initInstance();
|
||||||
|
|
||||||
/*
|
|
||||||
DOCUMENTATION: uses LOG_REQUESTS environment variable
|
|
||||||
|
|
||||||
# only log 200 and 204
|
|
||||||
LOG_REQUESTS=200 204
|
|
||||||
# log everything except 200 and 204
|
|
||||||
LOG_REQUESTS=-200 204
|
|
||||||
# log all requests
|
|
||||||
LOG_REQUESTS=-
|
|
||||||
*/
|
|
||||||
|
|
||||||
let logRequests = process.env["LOG_REQUESTS"] != undefined;
|
let logRequests = process.env["LOG_REQUESTS"] != undefined;
|
||||||
if (logRequests) {
|
if (logRequests) {
|
||||||
this.app.use(
|
this.app.use(
|
||||||
@ -60,7 +50,7 @@ export class FosscordServer extends Server {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
this.app.use(CORS);
|
this.app.use(CORS);
|
||||||
this.app.use(BodyParser({ inflate: true, limit: "10mb" }));
|
this.app.use(BodyParser({ inflate: true, limit: "10mb" }));
|
||||||
@ -85,19 +75,20 @@ export class FosscordServer extends Server {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
|
//app.use("/__development", )
|
||||||
|
//app.use("/__internals", )
|
||||||
app.use("/api/v6", api);
|
app.use("/api/v6", api);
|
||||||
app.use("/api/v7", api);
|
app.use("/api/v7", api);
|
||||||
app.use("/api/v8", api);
|
app.use("/api/v8", api);
|
||||||
app.use("/api/v9", api);
|
app.use("/api/v9", api);
|
||||||
app.use("/api", api); // allow unversioned requests
|
app.use("/api", api); // allow unversioned requests
|
||||||
|
|
||||||
this.app.use(ErrorHandler);
|
this.app.use(ErrorHandler);
|
||||||
TestClient(this.app);
|
TestClient(this.app);
|
||||||
|
|
||||||
if (logRequests) {
|
if (logRequests) console.log(red(`Warning: Request logging is enabled! This will spam your console!\nTo disable this, unset the 'LOG_REQUESTS' environment variable!`));
|
||||||
console.log(
|
|
||||||
"Warning: Request logging is enabled! This will spam your console!\nTo disable this, unset the 'LOG_REQUESTS' environment variable!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return super.start();
|
return super.start();
|
||||||
}
|
}
|
||||||
}
|
};
|
@ -13,10 +13,12 @@ export const NO_AUTHORIZATION_ROUTES = [
|
|||||||
"/ping",
|
"/ping",
|
||||||
"/gateway",
|
"/gateway",
|
||||||
"/experiments",
|
"/experiments",
|
||||||
|
"/updates",
|
||||||
|
"/downloads/",
|
||||||
// Public kubernetes integration
|
// Public kubernetes integration
|
||||||
"/-/readyz",
|
"/-/readyz",
|
||||||
"/-/healthz",
|
"/-/healthz",
|
||||||
//Client nalytics
|
// Client analytics
|
||||||
"/science",
|
"/science",
|
||||||
"/track",
|
"/track",
|
||||||
// Public policy pages
|
// Public policy pages
|
||||||
|
19
api/src/routes/downloads.ts
Normal file
19
api/src/routes/downloads.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
import { Relase, Config } from "@fosscord/util";
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get("/:branch", route({}), async (req: Request, res: Response) => {
|
||||||
|
const { client } = Config.get();
|
||||||
|
const { branch } = req.params;
|
||||||
|
const { platform } = req.query;
|
||||||
|
|
||||||
|
if(!platform || !["linux", "osx", "win"].includes(platform.toString())) return res.status(404)
|
||||||
|
|
||||||
|
const relase = await Relase.findOneOrFail({ name: client.relases.upstreamVersion });
|
||||||
|
|
||||||
|
res.redirect(relase[`win_url`]);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
20
api/src/routes/updates.ts
Normal file
20
api/src/routes/updates.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { Router, Response, Request } from "express";
|
||||||
|
import { route } from "@fosscord/api";
|
||||||
|
import { Config, Relase } from "@fosscord/util";
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
|
const { client } = Config.get();
|
||||||
|
|
||||||
|
const relase = await Relase.findOneOrFail({ name: client.relases.upstreamVersion})
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
name: relase.name,
|
||||||
|
pub_date: relase.pub_date,
|
||||||
|
url: relase.url,
|
||||||
|
notes: relase.notes
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
@ -181,6 +181,10 @@ export interface ConfigValue {
|
|||||||
},
|
},
|
||||||
client: {
|
client: {
|
||||||
useTestClient: Boolean;
|
useTestClient: Boolean;
|
||||||
|
relases: {
|
||||||
|
useLocalRelases: Boolean; //TODO
|
||||||
|
upstreamVersion: string;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
metrics: {
|
metrics: {
|
||||||
timeout: number;
|
timeout: number;
|
||||||
@ -365,7 +369,11 @@ export const DefaultConfigOptions: ConfigValue = {
|
|||||||
allowRaws: false
|
allowRaws: false
|
||||||
},
|
},
|
||||||
client: {
|
client: {
|
||||||
useTestClient: true
|
useTestClient: true,
|
||||||
|
relases: {
|
||||||
|
useLocalRelases: true,
|
||||||
|
upstreamVersion: "0.0.264"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
metrics: {
|
metrics: {
|
||||||
timeout: 30000
|
timeout: 30000
|
||||||
|
26
util/src/entities/clientRelase.ts
Normal file
26
util/src/entities/clientRelase.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { Column, Entity} from "typeorm";
|
||||||
|
import { BaseClass } from "./BaseClass";
|
||||||
|
|
||||||
|
@Entity("client_relase")
|
||||||
|
export class Relase extends BaseClass {
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
pub_date: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
url: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
deb_url: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
osx_url: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
win_url: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
notes?: string;
|
||||||
|
}
|
@ -26,3 +26,4 @@ export * from "./Template";
|
|||||||
export * from "./User";
|
export * from "./User";
|
||||||
export * from "./VoiceState";
|
export * from "./VoiceState";
|
||||||
export * from "./Webhook";
|
export * from "./Webhook";
|
||||||
|
export * from "./clientRelase";
|
Loading…
x
Reference in New Issue
Block a user