micromata / http-fake-backend

Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
MIT License
311 stars 21 forks source link

Cannot serve files (png) #15

Closed schmaluk closed 6 years ago

schmaluk commented 6 years ago
'use strict';

const SetupEndpoint = require('./setup/setup.js');

module.exports = SetupEndpoint({
    name: 'attachment',
    urls: [{
                   params: '/{file}',
                   requests: [{
                       sendFile: true,
                       mimeType: 'application/pdf',
                       //response: '/attachments/1.png',

                       response: '/attachments/test.pdf'
                   }]
               }
               ]
});

I get the error message:

2018-02-06/16:40:42.573, [response] http://localhost:8081: get /api/app/v6/attachment/test.pdf {} 500 (51ms)
2018-02-06/16:40:44.721, [log,connection,client,error] message: Parse Error, stack: Error: Parse Error
    at Error (native)
2018-02-06/16:40:44.728, [log,info] data: Received payload:null
Debug: internal, implementation, error 
    /project/attachments/test.pdf:1
(function (exports, require, module, __filename, __dirname) { %PDF-1.3
                                                              ^

SyntaxError: Unexpected token %
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at handler (/project/server/api/setup/setup.js:40:44)
2018-02-06/16:40:44.724, [response] http://localhost:8081: get /api/app/v6/attachment/test.pdf {} 500 (25ms)
mischah commented 6 years ago

https://github.com/micromata/http-fake-backend/blob/master/server/api/fileTypes.js should work on your machine too.

It seems, that you are not using the latest version of the fake backend.

Can you check the version number in the package.json? It should be > than 4. See releases.