mirror of
https://github.com/seejohnrun/haste-server
synced 2025-07-16 10:03:45 -07:00
Move storage mechanism to new object
This commit is contained in:
parent
b173cdd144
commit
fec02cfead
3 changed files with 49 additions and 31 deletions
10
server.js
10
server.js
|
@ -6,6 +6,7 @@ var winston = require('winston');
|
|||
|
||||
var StaticHandler = require('./lib/static_handler');
|
||||
var DocumentHandler = require('./lib/document_handler');
|
||||
var FileDocumentStore = require('./lib/file_document_store');
|
||||
|
||||
// Load the configuration and set some defaults
|
||||
var config = JSON.parse(fs.readFileSync('config.js', 'utf8'));
|
||||
|
@ -36,14 +37,19 @@ http.createServer(function(request, response) {
|
|||
|
||||
// Looking to add a new doc
|
||||
if (incoming.pathname.match(/^\/documents$/) && request.method == 'POST') {
|
||||
handler = new DocumentHandler({ keyLength: config.keyLength });
|
||||
handler = new DocumentHandler({
|
||||
keyLength: config.keyLength,
|
||||
store: new FileDocumentStore('./data')
|
||||
});
|
||||
return handler.handlePost(request, response);
|
||||
}
|
||||
|
||||
// Looking up a doc
|
||||
var match = incoming.pathname.match(/^\/documents\/([A-Za-z0-9]+)$/);
|
||||
if (request.method == 'GET' && match) {
|
||||
handler = new DocumentHandler();
|
||||
handler = new DocumentHandler({
|
||||
store: new FileDocumentStore('./data')
|
||||
});
|
||||
return handler.handleGet(match[1], response);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue