Skip to content

Commit 44bfb23

Browse files
author
Walker Leite
committed
feat(server): add client server
1 parent 3e350ae commit 44bfb23

File tree

7 files changed

+39
-19
lines changed

7 files changed

+39
-19
lines changed

template/.eslintrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

template/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import app from './server/server'
2+
import express from 'express'
3+
4+
app.use(express.static('client'))
5+
app.on('started', () => {
6+
const baseUrl = app.get('url').replace(/\/$/, '')
7+
console.log('Browse your CLIENT files at %s', baseUrl)
8+
})
9+
10+
if (require.main === module)
11+
app.start();
12+
13+
export default app

template/server/boot/root.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default function(server) {
2-
// Install a `/` route that returns server status
2+
// Install a `/api` route that returns server status
33
var router = server.loopback.Router();
4-
router.get('/', server.loopback.status());
4+
router.get('/api', server.loopback.status());
55
server.use(router);
66
};

template/server/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ app.start = function() {
1010
httpServer = app.listen(function() {
1111
app.emit('started');
1212
var baseUrl = app.get('url').replace(/\/$/, '');
13-
console.log('API server listening at: %s', baseUrl);
13+
console.log('API server listening at: %s', baseUrl + '/api');
1414
if (app.get('loopback-component-explorer')) {
1515
var explorerPath = app.get('loopback-component-explorer').mountPath;
1616
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);

template/test/server/boot.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('boot process', () => {
2626
describe('root.js', () => {
2727
it('should return server status by root.js', (done) => {
2828
let conn = server.listen(8000, () => {
29-
request(server).get('/').then((res) => {
29+
request(server).get('/api').then((res) => {
3030
expect(res).to.have.status(200);
3131
expect(res.body).to.have.property('started');
3232
expect(res.body).to.have.property('uptime');

template/test/server/index.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import server from '../../index.js';
2+
3+
describe('Project Index', () => {
4+
beforeEach(done => {
5+
server.once('started', done)
6+
server.start()
7+
})
8+
9+
afterEach(() => server.close())
10+
11+
it('should serve client files', done => {
12+
request(server).get('/index.html').end((err, res) => {
13+
expect(err).to.be.null
14+
expect(res).to.have.status(200)
15+
done()
16+
})
17+
});
18+
});

template/test/server/server.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import app from '../../server/server.js';
22

33
describe('Application', () => {
44
it('should start the server', (done) => {
5-
app.addListener('started', done);
5+
app.once('started', () => {
6+
app.close()
7+
done()
8+
});
69
app.start();
710
});
811
});

0 commit comments

Comments
 (0)