-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapp.js
More file actions
89 lines (76 loc) · 2.12 KB
/
app.js
File metadata and controls
89 lines (76 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import fs from "fs";
import path from "path";
import zlib from "zlib";
import koa from "koa";
import cors from "kcors";
import route from "koa-route";
import logger from "koa-logger";
import favicon from "koa-favicon";
import compress from "koa-compress";
import serve from "koa-static";
import views from "koa-views";
import bodyparser from "koa-bodyparser";
import debuglog from "debug";
import { fileURLToPath } from "url";
import { dirname } from "path";
import index from "./routes/index.js";
import recent from "./routes/recent.js";
import search from "./routes/search.js";
import share from "./routes/share.js";
import { slack, oauth } from "./routes/slack.js";
import { constants } from "zlib";
const debug = debuglog("combine.fm");
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
process.env.VUE_ENV = "server";
const app = new koa();
if (process.env.NODE_ENV === "production") {
app.proxy = true;
}
app.use(bodyparser());
app.use(cors());
app.use(
compress({
filter(content_type) {
return /text/i.test(content_type);
},
threshold: 2048,
gzip: {
flush: constants.Z_SYNC_FLUSH
},
deflate: {
flush: constants.Z_SYNC_FLUSH
},
br: false
})
);
app.use(favicon(path.join(__dirname, "/public/assets/images/favicon.png")));
app.use(logger());
app.use(serve("public", { maxage: 31536000000 }));
const manifest = JSON.parse(
fs.readFileSync(path.join(__dirname, "/public/dist/manifest.json"))
);
app.use(async function(ctx, next) {
ctx.state.manifest = manifest;
await next();
});
app.use(
views(path.resolve(__dirname, "./views"), {
map: {
html: "ejs"
}
})
);
app.use(route.get("/", index));
app.use(route.get("/recent", recent));
app.use(route.post("/search", search));
app.use(route.get("/:service/:type/:id.:format?", share));
app.use(route.post("/slack", slack));
app.use(route.get("/slack", slack));
app.use(route.get("/oauth", oauth));
if (process.argv[1] === __filename) {
app.listen(process.env.PORT || 3000, () => {
debug(`Koa HTTP server listening on port ${process.env.PORT || 3000}`);
});
}
export default app;