forked from remy/mit-license
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
70 lines (61 loc) · 1.76 KB
/
server.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
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
/*
IMPORTANT: Set the `github_token` environment variable to a personal access token
with at least the `public_repo` scope for the API.
Server port: The `PORT` environment variable can also be set to control the port the server
should be hosted on.
*/
const express = require('express')
const minify = require('express-minify')
const favicon = require('serve-favicon')
const postcssMiddleware = require('postcss-middleware')
const tempDirectory = require('temp-dir')
const path = require('path')
// Server
const PORT = process.env.PORT || 8080
// Prepare application
const app = express()
app.use(
minify({
cache: tempDirectory
})
)
app.use(favicon(path.join(__dirname, 'favicon.ico')))
app.set('views', path.join(__dirname, '/licenses'))
// Setup static files
app.use('/robots.txt', express.static('robots.txt'))
app.use('/favicon.ico', express.static(`${__dirname}/favicon.ico`))
app.use(
'/themes',
postcssMiddleware({
plugins: [
require('postcss-preset-env')({
overrideBrowserslist: '>= 0%'
})
],
src (request) {
return path.join(__dirname, 'themes', request.path)
}
}),
express.static('themes')
)
// Middleware
// CORS
app.use(require('cors')())
// Parse URL-encoded bodies (as sent by HTML forms)
app.use(
express.urlencoded({
extended: true
})
)
// Parse JSON bodies (as sent by API clients)
app.use(express.json())
// Capture the id from the subdomain and options from parts of the url
app.use(require('./middleware/load-user'))
app.use(require('./middleware/load-options'))
// HTTP endpoints
app.post('/', require('./routes/post'))
app.get('/*', require('./routes/get'))
// Start listening for HTTP requests
app.listen(PORT, () => {
console.log(`🚀 on http://localhost:${PORT}`)
})