-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
67 lines (53 loc) · 1.49 KB
/
app.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
'use strict';
const express = require('express');
const app = express();
const expressSvelte = require('express-svelte');
app.set('json spaces', 2);
// Express svelte setup
app.use(expressSvelte({
// Support legacy browsers only on production
legacy: process.env.NODE_ENV !== 'development',
hydratable: true,
viewsDirname: __dirname + '/views',
bundlesDirname: __dirname + '/public/dist',
bundlesHost: '/public/dist',
bundlesPattern: '[name][extname]',
env: 'development'
}));
// Serve public files
app.use('/public', express.static(__dirname + '/public'));
// Home page
app.get('/', function (req, res, next) {
res.svelte('Home/Home.svelte', {
globalStores: {
counter: 0
},
globalProps: {
title: 'Express Svelte Example'
},
props: {
value: 'View prop'
}
});
});
// Non matched routes handler
app.use(function (req, res, next) {
console.log('app.js 404 url:%s', req.originalUrl);
res.status(404).json({
success: false,
statusCode: 404
});
});
// Error handler
app.use(function (err, req, res, next) {
console.error('app.js 500 url:%s. Error: %s %s %s', req.originalUrl, err.code || null, err.message, err.stack);
res.status(500).json({
success: false,
statusCode: 500,
code: err.code || null,
message: err.message,
stack: err.stack
});
});
app.listen(4500);
console.log('app.js Listening at port:4500');