Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ Setting a wildcard (`*`) is also supported, but not recommended. It's neither a

```
ACKEE_ALLOW_ORIGIN="*"
```
```

## Base url
Change the url path at which Ackee listens. You can use this in conjunction with a reverse proxy like nginx or traefik to publish ackee on `https://example.com/ackee/` instead of `https://ackee.example.com/`

```
ACKEE_BASEURL=/ackee
```

*Do not add a trailing `/`.*
4 changes: 2 additions & 2 deletions src/healthcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const exit = (healthy) => process.exit(healthy === true ? 0 : 1)

const check = () => Promise.all([
checkMongoDB(config.dbUrl),
checkServer(`http://localhost:${ config.port }`),
checkApi(`http://localhost:${ config.port }/.well-known/apollo/server-health`),
checkServer(`http://localhost:${ config.port }${ config.baseUrl }/`),
checkApi(`http://localhost:${ config.port }${ config.baseUrl }/.well-known/apollo/server-health`),
])

const handleSuccess = () => {
Expand Down
21 changes: 13 additions & 8 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,43 +93,48 @@ const apolloServer = createApolloServer(ApolloServer, {
context: createMicroContext,
})

const graphqlPath = '/api'
const graphqlPath = `${ config.baseUrl }/api`
const graphqlHandler = apolloServer.createHandler({ path: graphqlPath })

const routes = [

get('/', async (req, res) => {
get(`${ config.baseUrl }/`, async (req, res) => {
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.end(await index)
}),
get('/index.html', async (req, res) => {
get(`${ config.baseUrl }/index.html`, async (req, res) => {
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.end(await index)
}),
get('/favicon.ico', async (req, res) => {
get(`${ config.baseUrl }/favicon.ico`, async (req, res) => {
res.setHeader('Content-Type', 'image/vnd.microsoft.icon')
res.end(await favicon)
}),
get('/index.css', async (req, res) => {
get(`${ config.baseUrl }/index.css`, async (req, res) => {
res.setHeader('Content-Type', 'text/css; charset=utf-8')
res.end(await styles)
}),
get('/index.js', async (req, res) => {
get(`${ config.baseUrl }/index.js`, async (req, res) => {
res.setHeader('Content-Type', 'text/javascript; charset=utf-8')
res.end(await scripts)
}),
get('/tracker.js', async (req, res) => {
get(`${ config.baseUrl }/tracker.js`, async (req, res) => {
res.setHeader('Content-Type', 'text/javascript; charset=utf-8')
res.end(await tracker)
}),
customTracker.exists === true ? get(customTracker.url, async (req, res) => {
res.setHeader('Content-Type', 'text/javascript; charset=utf-8')
res.end(await tracker)
}) : undefined,
config.baseUrl !== '' ? get(config.baseUrl, (req, res) => {
res.statusCode = 302
res.setHeader('Location', `${ config.baseUrl }/`)
res.end()
}) : undefined,

post(graphqlPath, graphqlHandler),
get(graphqlPath, graphqlHandler),
get('/.well-known/apollo/server-health', graphqlHandler),
get(`${ config.baseUrl }/.well-known/apollo/server-health`, graphqlHandler),

get('/*', notFound),
post('/*', notFound),
Expand Down
2 changes: 2 additions & 0 deletions src/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ const { writeFile, readFile } = require('fs').promises
const layout = require('../utils/layout')
const config = require('../utils/config')
const customTracker = require('../utils/customTracker')
const baseUrl = require('../utils/baseUrl')
const signale = require('../utils/signale')

const index = () => {
return layout('<div id="main"></div>', 'favicon.ico', [ 'index.css' ], [ 'index.js' ], {
isDemoMode: config.isDemoMode,
customTracker,
baseUrl,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/scripts/api/links/createHttpLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userTimeZone from '../../../../utils/timeZone'

export default () => {
return new BatchHttpLink({
uri: '/api',
uri: './api',
headers: {
'Time-Zone': userTimeZone,
},
Expand Down
4 changes: 2 additions & 2 deletions src/ui/scripts/components/modals/ModalDomainEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const ModalDomainEdit = (props) => {
const idId = shortId()
const embedId = shortId()

const trackerUrl = window.env.customTracker.url || '/tracker.js'
const trackerUrl = window.env.customTracker.url || `${ decodeURIComponent(window.env.baseUrl.url) }/tracker.js`
const srcUrl = (new URL(trackerUrl, location.href)).href
const serverUrl = location.origin
const serverUrl = `${ location.origin }${ decodeURIComponent(window.env.baseUrl.url) }`

return (
h('form', { className: 'card', onSubmit },
Expand Down
14 changes: 14 additions & 0 deletions src/utils/baseUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

const sanitizeFilename = require('sanitize-filename')

const name = process.env.ACKEE_BASEURL
const exists = name != null && name !== ''

module.exports = {
exists,
url: exists === true ? `${ encodeURIComponent(name) }` : '',
path: exists === true ? `${ sanitizeFilename(name) }` : '',
}

console.log(module.exports.path)
1 change: 1 addition & 0 deletions src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = new Proxy({}, {
isDemoMode: process.env.ACKEE_DEMO === 'true',
isDevelopmentMode: process.env.NODE_ENV === 'development',
isPreBuildMode: process.env.BUILD_ENV === 'pre',
baseUrl: process.env.ACKEE_BASEURL || '',
}

return data[prop]
Expand Down