-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
455 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import path from 'path'; | ||
import express from 'express'; | ||
|
||
const PORT = 8092; | ||
|
||
// This is the server that runs on "yarn serve". | ||
// It works by serving the statically generated .html files on /out. | ||
// Of course, before starting this server you should export the project with "yarn export" | ||
const mainApp = express(); | ||
|
||
const rootPath = path.resolve(path.join(__dirname, 'out')); | ||
|
||
const staticConfig = { | ||
extensions: ['html'], // when requesting "/aaa/bbb", also look for "/aaa/bbb.html" | ||
redirect: true, | ||
index: 'index.html', | ||
}; | ||
|
||
// serve the actual generated static files | ||
mainApp.use(express.static(path.join(rootPath), staticConfig)); | ||
|
||
// redirects "/something/that/doesnt_exist" -> "404.html" | ||
mainApp.all('*', (req, res) => { | ||
res.status(404).sendFile(path.join(rootPath, '404.html')); | ||
}); | ||
|
||
console.log(`Server listening on http://localhost:${PORT}/`); | ||
|
||
const server = mainApp.listen(PORT); | ||
|
||
server.on('connection', (socket) => { | ||
socket.setNoDelay(true); | ||
}); |
Oops, something went wrong.