-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 1015 Bytes
/
index.js
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
const express = require('express');
const { Git : Server } = require('node-git-server');
const path = require('path');
const app = express();
const port = parseInt(process.env.PORT ?? 8080);
const repos = new Server(path.normalize(path.resolve(__dirname, 'repos')), {
autoCreate: false,
checkout: false
});
repos.on('push', push => push.reject());
repos.on('tag', tag => tag.reject());
// only for development
// const cors = require('cors');
// app.use(cors());
app.use(express.static(path.resolve(__dirname, 'docs')));
app.use('/git', (req, res) => repos.handle(req, res));
app.get('*', function (req, res) {
res.sendFile(path.resolve(__dirname, 'docs', 'index.html'));
});
app.listen(port, () => {
console.log(`glint-repo-host running at http://localhost:${port}`);
repos.list((err, result) => {
if (!result || result.length === 0) {
console.log("No repositories available...");
} else {
console.log(result.map(name => `http://localhost:${port}/${name}`));
}
});
});