UNPKG

954 BJavaScriptView Raw
1const express = require('express')
2const glob = require('glob')
3const path = require('path')
4const { createReloadable, isDevelopment } = require('@artsy/express-reloadable')
5
6const app = express()
7
8if (isDevelopment) {
9 const mountAndReload = createReloadable(app, require)
10
11 const modules = glob.sync('./components/**/*.js').map(name => path.resolve(name))
12
13 // Note that if you need to mount an app at a particular root (`/api`), pass
14 // in `mountPoint` as an option.
15 app.use('/api', mountAndReload(path.resolve(__dirname, 'api'), {
16 mountPoint: '/api',
17 watchModules: [
18 ...modules
19 // or, `some-linked-npm-module`
20 ]
21 }))
22
23 // Otherwise, just pass in the path to the express app and everything is taken care of
24 mountAndReload(path.resolve(__dirname, 'client'))
25} else {
26 app.use('/api', require('./api'))
27 app.use(require('./client'))
28}
29
30app.listen(3000, () => {
31 console.log('Listening on http://localhost:3000')
32})